User.fromJson constructor

User.fromJson(
  1. Map<String, dynamic> jsonRes
)

Implementation

factory User.fromJson(Map<String, dynamic> jsonRes) {
  final roles = jsonRes['roles'] is List ? <Roles>[] : null;
  if (roles != null) {
    for (final dynamic item in jsonRes['roles']!) {
      if (item != null) {
        tryCatch(() {
          roles.add(Roles.fromJson(asT<Map<String, dynamic>>(item)!));
        });
      }
    }
  }

  final resourcesCategories =
  jsonRes['resourcesCategories'] is List ? <Object>[] : null;
  if (resourcesCategories != null) {
    for (final dynamic item in jsonRes['resourcesCategories']!) {
      if (item != null) {
        tryCatch(() {
          resourcesCategories.add(asT<Object>(item)!);
        });
      }
    }
  }
  return User(
    id: asT<int>(jsonRes['id'])!,
    loginNumber: asT<String>(jsonRes['loginNumber'])!,
    nickName: asT<String>(jsonRes['nickName'])!,
    email: asT<String>(jsonRes['email']??'')!,
    picture: asT<String>(jsonRes['picture'])!,
    phone: asT<String>(jsonRes['phone']??'')!,
    loginTime: asT<String>(jsonRes['loginTime']??'')!,
    type: asT<int>(jsonRes['type'])!,
    resourcesCategories: resourcesCategories!,
    status: asT<int>(jsonRes['status'])!,
  );
}