滑块小部件更改点在文本文件上的位置

Slider widget changing the position of the dot over a texfile

是否可以通过外部输入修改滑块小部件的值?例如来自文本字段? 例如,将 50 写入文本字段,滑块的点将更改为位置 50。

我不知道为什么需要这样做,但这是代码

这是滑块小部件

  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;
        });
      },
    );
  }

这是包含我们之前创建的文本表单域和滑块小部件的列小部件。

Column(
      children: [
              TextFormField(
                onChanged: (val){
                  setState((){
                    _value = double.parse(val);
                  });
                },
              ),
              SliderWidget()
            ],
          )
  1. 确保用户只键入数字。
  2. 确保用户键入的数字不大于滑块的最大值。