如果发生以下情况,如何管理服务器响应
status
200
.
@JsonSerializable(nullable: false)
class LoginResponse {
final String error;
final int status;
final List<User> userList;
LoginResponse({this.error, this.status, this.userList});
factory LoginResponse.fromJson(Map repJson){
List<dynamic> userListResp=repJson['userData'];
List<User> userList=userListResp.map((e)=>User.fromUser(e)).toList();
int s=repJson['status'];
if(s==200){
return LoginResponse(error:repJson['error'],status: repJson['status'],userList:userList);
} else{
return LoginResponse(error:repJson['error'],status: repJson['status']);
}}}
class User{
String cust_id;
String cust_name;
String cust_email;
String cust_mob;
User({this.cust_id,this.cust_name,this.cust_email,this.cust_mob});
factory User.fromUser(Map userJson){
return User(cust_id: userJson['cust_id'],cust_name: userJson['cust_name'],
cust_email: userJson['cust_email'],cust_mob: userJson['cust_mob']);
}
}
发生错误时的服务器响应
{"error":"1","status":201,"message":"Entered email id already exist in our records"}
{
"error":"0",
"status":200,
"userData":[
{
"cust_id":"87",
"cust_name":"kio",
"cust_email":"kio1@kio.com",
"cust_gend":null,
"cust_dob":null,
"cust_mob":"098998899889588",
"cust_pass":"e10adc3949ba59abbe56e057f20f883e",
"cust_age":null,
"device_type":"android",
"device_token":"eNWqzDwxqsQ:APA91bF-uK1MI11D3SgHGSw7Omv1imjDrPKBBCrN9JgmyJppHsNVeG5l56EkCCd5ZMaxL_ehQzVhtoEj0fTNB55wYGJt5BqYVvwfAb7HrBqwb_21M6VFPuF6LQINkvE1offQgZYweROO",
"status":"0",
"createAt":"2019-01-31 18:45:19",
"updatedAt":"0000-00-00 00:00:00",
"login_type":"",
"login_id":null,
"is_guest":"0",
"auth_token":"",
"forgot_token":null
}]
}
当用户数据不存在或为空时,我如何管理?我尝试管理
status code is 201
NoSuchMethodError:对null调用了方法“map”。