login method

Future<User> login(
  1. Map<String, dynamic> json
)

Implementation

Future<User> login(Map<String, dynamic> json) async {
  Response resp = await _userProvider.login(json);
  dynamic headers = resp.headers;
  dynamic body = resp.body;
  final prefs = GetStorage();

  dynamic convertBody = convertUtf8ToObject(body);
  ServerRespDto serverRespDto = ServerRespDto(
      code: convertBody["code"],
      msg: convertBody["msg"],
      data: convertBody["data"]);
  dynamic convertHeader = convertUtf8ToObject(headers);

  if (serverRespDto.code == 1) {
    User newUser = User.fromJson(serverRespDto.data);

    newUser.token = convertHeader["authorization"] ?? "no auth key";

    return newUser;
  } else {
    prefs.write("loginFailureMsg", serverRespDto.msg);
    return User();
  }
}