Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Slider - doesn't show label

I've this Slider but it's not showing the label anywhere.

Is this the normal behaviour?

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

like image 868
alexpfx Avatar asked Mar 19 '19 04:03

alexpfx


Video Answer


2 Answers

Try set up divisions value to 9. You will see the label on each step of the values. seems like this label property is not a text label of the slider.

like image 92
Yuna Avatar answered Sep 20 '22 18:09

Yuna


Ran into this and what seems to fix it is to set up the divisions property of the Slider

and interpolate the string Power with the changing value

Slider(
                        value: sliderValue,
                        min: 0,
                        max: 9,
                        divisions: 9,
                        label: "Power: ${sliderValue.round().toString()}",
                        onChanged: (double value) {
                          setState(() {
                            sliderValue = value;
                          });
                        },
                      ),
like image 41
butter1v9 Avatar answered Sep 21 '22 18:09

butter1v9