Home > Net >  Slider widget changing the position of the dot over a texfile
Slider widget changing the position of the dot over a texfile

Time:05-27

Is it possible, to modify the slider widget value through a input from outside? For example from a text field? Writing 50 to the textfield for example, the dot of the slider would change to position 50.

CodePudding user response:

i have no idea why that would be necessary but here is the code

This is the slider widget

  double _value = 50;

  Slider SliderWidget() {
    return Slider(
      min: 0,
      max: 100, //set the maximum value because it will crash if the user enters a number greater than the value
      value: _value,
      onChanged: (value) {
        setState(() {
          _value = value;
        });
      },
    );
  }

and this is the column widget that contains the textformfield and the slider widget we created earlier.

Column(
      children: [
              TextFormField(
                onChanged: (val){
                  setState((){
                    _value = double.parse(val);
                  });
                },
              ),
              SliderWidget()
            ],
          )
  1. Make sure the user only types numbers.
  2. Make sure the user doesnt type a number greater than that of the maximum value of the slider.
  • Related