try { response = await postMethod( uri: url, body: body, mobileNo: custMobileNo, ); } catch (e) { response = null; } if (response != null && response.statusCode == 200) { try { return CustomerResponse.fromJson( convert.jsonDecode(response.data)["data"][0]); } catch (e) { CustomerResponse(custList: response.data); } } else { CustomerResponse(custList: response.data); }
我的回复文件。
工厂 CustomerResponse.fromJson(Map
Map
[![Response](https://i.stack.imgur.com/dML3n.png)](https://i.stack.imgur.com/dML3n.png)
我想发送数据到服务器。 并显示成功消息。给用户
您应该创建一个
CustomerList
对象并将它们添加到 custList
。有样品:
...
if (response != null && response.statusCode == 200) {
try {
return CustomerResponse.fromJson(
convert.jsonDecode(response.data)["data"][0]);
} catch (e) {
List<CustomerList> customerList = [];
//data or customerData what name you give
for (var item in convert.jsonDecode(response.data)["data"]) {
customerList.add(CustomerList.fromJson(item));
}
CustomerResponse(custList: customerList);
...
}
}
...