【发布时间】:2020-12-18 16:28:31
【问题描述】:
【问题讨论】:
【问题讨论】:
您可以使用GlobalKey 来完成此操作。把TextFormField作为孩子放到Form
GlobalKey<FormState> _key = GlobalKey<FormState>();
class MyForm extends StatelessWidget
{
MyForm({Key key}) : super(key:key);
@override
Widget build(BuildContext context) {
return Form(
key: _key,
autovalidate: true,
child: // All the form fields will go here
);
}
}
之后就可以使用了
_key.currentState.reset()
在另一个类中,它将表单内的每个字段重置回其initialValue
【讨论】: