Flutter Slider-不显示标签

时间:2019-03-19 04:07:41

标签: flutter flutter-layout

我有这个Slider,但是它没有在任何地方显示标签。

这是正常行为吗?

double _value;

  _buildEditModeWidget() {
    return Expanded(
        child: Column(
      children: <Widget>[
        SizedBox(height: 60,),
        Slider(
        label: "Power: ",
          min: 0,
          max: 9,
          value: _value,
          onChanged: (double newValue) {
            setState(() {
              _value = newValue;
            });
          },
        )
      ],
    ));
  }





  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(border: Border(top: BorderSide(width: 1))),
      height: editMode ? _editModeHeight : _readOnlyHeight,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.all(8),
            child: AspectRatio(
              aspectRatio: 0.9,
              child: (extension(widget.model.team.shieldImage) != ".svg")
                  ? Image.network(
                      widget.model.team.shieldImage,
                      fit: BoxFit.scaleDown,
                      filterQuality: FilterQuality.high,
                    )
                  : SvgPicture.network(
                      widget.model.team.shieldImage,
                      fit: BoxFit.scaleDown,
                    ),
            ),
          ),
          ScopedModelDescendant<TeamModel>(
            builder: (BuildContext context, Widget child, TeamModel model) {
              return editMode ? _buildEditModeWidget() : _buildReadOnlyWidget();
            },
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Container(
                child: editMode
                    ? IconButton(
                  icon: Icon(Icons.check),
                  onPressed: () {
                    setState(() {
                      widget.model.updateTeam(_teamNameController.text, 0);
                      editMode = false;
                    });
                  },
                )
                    : IconButton(
                  key: _key,
                  icon: Icon(Icons.edit),
                  onPressed: () {
                    setState(() {
                      editMode = true;
                    });
                  },
                ),
              )
              ],
          )
        ],
      ),
    );
  }

enter image description here

3 个答案:

答案 0 :(得分:1)

尝试将除法值设置为9。您将在值的每个步骤上看到标签。似乎此label属性不是滑块的文本标签。

答案 1 :(得分:0)

遇到这个问题,似乎可以解决这个问题的是设置 Slider 的 Divisions 属性

并用变化的值插入字符串 Power

Slider(
                        value: sliderValue,
                        min: 0,
                        max: 9,
                        divisions: 9,
                        label: "Power: ${sliderValue.round().toString()}",
                        onChanged: (double value) {
                          setState(() {
                            sliderValue = value;
                          });
                        },
                      ),

答案 2 :(得分:-3)

在 Slider witget 上标记视觉,属性添加您的代码; “部门”属性,(Lütfen Division propertiessini kullanın aksi halde slider da label görünmez),