[英]how to setState() using Flutter TextFormField
validator: (value) {
if (value.isEmpty) {
_casing.depth = 0;
} else if (double.tryParse(value) != null) {
// setState(() {
_casing.depth = double.tryParse(value);
// });
} else {
_casing.depth = 0;
return kTextFieldError;
}
return null;
},
This returns an error that says unable to setState while currently doing so.这将返回一个错误,指出当前执行此操作时无法设置状态。 What I need is as the user inputs (or finishes either by clicking ok or tapping anywhere which automatically hides keyboard), I want to use the input value to calculate numbers in the parent widget
我需要的是作为用户输入(或通过单击确定或点击自动隐藏键盘的任何位置完成),我想使用输入值来计算父小部件中的数字
you can use the onChanged
property of TextFormField
您可以使用
TextFormField
的onChanged
属性
onChanged:(value){
if (value.isEmpty) {
_casing.depth = 0;
} else if (double.tryParse(value) != null) {
// setState(() {
_casing.depth = double.tryParse(value);
// });
} else {
_casing.depth = 0;
return kTextFieldError;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.