void Funtion(String)不能分配给void Functiontion(String?


Widget _buildName(){
return TextFormField(
decoration: InputDecoration(labelText: "Name"),
validator: (String value){
if(value.isEmpty){
return 'Name is Required';
}
},
onSaved: (String value){
_name = value;
}
);
} 

如果检查onSavedvalidator方法,它们都提供可为null的字符串

  • FormFieldSetter<String>? onSaved,
  • FormFieldValidator<String>? validator,

所以它将是

TextFormField(
decoration: InputDecoration(labelText: "Name"),
validator: (String? value) {
// add other condition
if (value == null) {
return 'Name is Required';
}
return null;
},
onSaved: (String? value) {
_name = value; 
});

有关TextFormField 的更多信息

相关内容

  • 没有找到相关文章