当我更改值时,Flutter 抛出 "Invalid double" 错误

Flutter throws an "Invalid double" error when i change the value

我正在尝试从文本字段中获取值并在滑块中使用该值。我已经实现了我想要的,但是当我更改文本字段的值时出现错误。

错误:

The following FormatException was thrown while dispatching notifications for TextEditingController:
Invalid double

代码:

  double minValue = 0.0;
  double maxValue = 25000.0;
  double _availableValue = 12450.0;

  void _setAmountValue() {
    print('Amount: ${double.parse(amountController.text)}');
    if (
        double.parse(amountController.text).roundToDouble() >= minValue &&
        double.parse(amountController.text).roundToDouble() <= maxValue
        ) {
      setState(() {
        _availableValue = double.parse(amountController.text).roundToDouble();
      });
    }
  }

TextField(
controller: amountController,
focusNode: amountFocus,
style: TextStyle(color: Color(0xff757575), fontSize: 15, fontFamily: 'Gilroy Medium'),
decoration: InputDecoration(hintText: "12,450.00",border: InputBorder.none,),maxLines: 1,),


Slider(
     value: availableValue.toDouble(),
     min: 0.0,
     max: 25000.0,
     onChanged: (double newValue) {
        setState(() {
          availableValue = newValue.toInt();
          // amountController.text = value.toString();
        });
      },
),

请帮我解决这个问题。提前致谢。

使用文本控制器设置滑块的值

void initState()
{
  super.initState();
  _sliderTextController.text=_sliderValue.toString();
}
double _sliderValue=50.0;

return Row(children: [
                  Slider(
                    min:0,
                    max:100,
                    value:_sliderValue,
                    onChanged: (value) => {
                     
                      setState((){_sliderValue=value;_sliderTextController.text=value.toString();})
                  },),
                  SizedBox(width:100,child:
                  TextFormField(controller: _sliderTextController,))
                ],);