Home > Blockchain >  How to set color in flutter from slider?
How to set color in flutter from slider?

Time:09-26

I have a list of colors const bgcolor = ['Colors.red','Colors.green','Colors.blue','Colors.purple']; I want to change the color as I slide forward. I can print the color but I want to set it in a container as color:... The value means double _value = 0;

 child: Slider(
                      value: _value,
                      label: _emojis[_value.toInt()],
                      min: 0.0,
                      max: 3.0,
                      divisions: 3,
                      onChangeStart: (double value) {},
                      onChangeEnd: (double value) {
                        print('${bgcolor[_value.toInt()]}');
                      },
                      onChanged: (double value) {
                        setState(() {
                          _value = value;
                        });

CodePudding user response:

You will need to create another variable that holds the selected color or set the color property of your container to bgcolor[_value].

Container(
                  color: bgcolor[_value],
                  child: Slider(
                    ...
                  ),
                ),
  • Related