Flutter抛出“无效的双重”当我更改值时错误
我正在尝试从Textfield获取值,并在滑块中使用该值。我已经实现了自己想要的东西,但是当我更改文本字段的价值时,我会遇到错误。
错误:
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();
});
},
),
请在此问题上帮助我。提前致谢。
I am trying to get the value from the Textfield and use that value in the slider. I have achieved what i want but i am getting error when i change the value of the textfield.
Error:
The following FormatException was thrown while dispatching notifications for TextEditingController:
Invalid double
Code:
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();
});
},
),
Please help me on this issue. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用文本控制器从滑块设置值
use the text controller to set the value from the slider