sách gpt4 ăn đã đi

http - flutter 如何处理 http 服务器端验证错误

In lại 作者:IT王子 更新时间:2023-10-29 06:46:00 25 4
mua khóa gpt4 giày nike

我正在尝试在登录表单上显示服务器端错误。我正在尝试在数据可用时更改状态。但它不工作。谁能帮忙

或者有什么更好的方法吗?

 Future 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);
trả về 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"];
});

} khác {
setState(() {
_autovalidate = true;
});
}
}

new Text(email_id_error),

服务器响应

{status_code: 4003, errors: {password: [can't be blank], email_id: [can't be blank]}}

câu trả lời hay nhất

你可以试试这个

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"];
});
}
} khác {
setState(() {
_autovalidate = true;
});
}
}

关于http - flutter 如何处理 http 服务器端验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162112/

25 4 0
IT王子
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress