颤振如何处理http服务器端验证错误
我试图在登录表单上显示服务器端错误。 我试图在数据可用时更改状态。 但它不起作用。有人能帮忙吗 或者有没有更好的方法颤振如何处理http服务器端验证错误,http,dart,flutter,Http,Dart,Flutter,我试图在登录表单上显示服务器端错误。 我试图在数据可用时更改状态。 但它不起作用。有人能帮忙吗 或者有没有更好的方法 Future<dynamic> apiRequest(map) async { String url = 'https://localhost/api/login'; var response = await http.post(Uri.encodeFull(url), body: map, headers: {"Accept": "
Future<dynamic> apiRequest(map) async {
String url = 'https://localhost/api/login';
var response = await http.post(Uri.encodeFull(url),
body: map, headers: {"Accept": "application/json"});
var res = json.decode(response.body);
return res;
}
void _submit() async {
if (this._formKey.currentState.validate()) {
_formKey.currentState.save(); // Save our form now.
var map = {
'email_id': '',
'password': '',
};
var hello = await apiRequest(map);
setState(() {
email_id_error = hello["errors"]["email_id"];
});
} else {
setState(() {
_autovalidate = true;
});
}
}
new Text(email_id_error),
你可以试试这个
void _submit() async {
if (this._formKey.currentState.validate()) {
_formKey.currentState.save(); // Save our form now.
var map = {
'email_id': '',
'password': '',
};
var hello = await apiRequest(map);
if(hello.statusCode ==4003){
setState(() {
email_id_error = hello.responseBody["errors"]["email_id"];
});
}
} else {
setState(() {
_autovalidate = true;
});
}
}
void _submit() async {
if (this._formKey.currentState.validate()) {
_formKey.currentState.save(); // Save our form now.
var map = {
'email_id': '',
'password': '',
};
var hello = await apiRequest(map);
if(hello.statusCode ==4003){
setState(() {
email_id_error = hello.responseBody["errors"]["email_id"];
});
}
} else {
setState(() {
_autovalidate = true;
});
}
}