Map <String, dynamic> customerFormErrors;
# Widget
TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Customer Email',
errorText: '${customerFormErrors.email}',
border: OutlineInputBorder(),
fillColor: mainColor,
prefixIcon: Icon(Icons.email),
),
onSaved: (value) {
this.customer.email = value;
},
),
);
# Submit Function
_submitForm(Customer customer) async {
Create a Customer
*/
Response response = await createCustomer(this.customer);
if (response.statusCode == 201 || response.statusCode == 200) {
// Customer has been added
Scaffold.of(context).showSnackBar(
SnackBar(backgroundColor: mainColor, content: Text('Added')));
} else {
// Notify him with errors
setState(() {
customerFormErrors = jsonDecode(response.body);
});
}
}
我正在发布到API,然后将错误响应正文附加到变量。 有没有办法将该变量绑定到TextFormField的errorText。
有点像angular,我们在其中使用类型安全运算符,例如以下{{error?.name}}吗?