英文:
TextFormField validator text
问题
I'm new to flutter. Is there any way to know if the validator text of a text form field is currently being shown on the screen? I would like to setState of a value if the validator is being shown. Thoughts?
英文:
I'm new to flutter. Is there any way to know if the validator text of a text form field is currently being shown on the screen? I would like to setState of a value if the validator is being shown. Thoughts?
答案1
得分: 2
你可以声明一个状态,然后更新它的值。
TextFormField(
validator: (value) {
if (value.isEmpty) {
setState(() {
_isValidatorVisible = true;
});
return '请输入一个值';
}
setState(() {
_isValidatorVisible = false;
});
return null;
},
),
在这个示例中,如果文本字段为空,你会显示一个指示器。由于你知道你正在显示指示器,你可以使用这个信息并设置状态。
英文:
You can declare a state and then update it's value.
TextFormField(
validator: (value) {
if (value.isEmpty) {
setState(() {
_isValidatorVisible = true;
});
return 'Please enter a value';
}
setState(() {
_isValidatorVisible = false;
});
return null;
},
),
In this example, if the TextField is empty you display an indicator. Since you know you showing the indicator, you can use that information and set the state.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论