【发布时间】:2021-10-03 03:11:24
【问题描述】:
我试图在单击按钮时保存表单,但它给了我一个错误,“无法调用方法,因为接收器可以为空”。我提供了一个空检查,但错误没有得到解决。任何帮助将不胜感激。
这里是代码
onPressed: () {
if (_formKey.currentState != null) {
_formKey.currentState.save(); // this gives the error
}
},
这个 onPressed 与提升的按钮链接,这里的 _formKey 是这样的:
// key to work with the form
final _formKey = GlobalKey<FormState>();
【问题讨论】: