import 'package:sk_base_mobile/models/dept.model.dart'; import 'package:sk_base_mobile/models/role.model.dart'; class UserInfoModel { UserInfoModel({ this.id, this.createdAt, this.updatedAt, this.username, this.psalt, this.nickname, this.avatar, this.qq, this.email, this.phone, this.remark, this.status, this.dept, this.roles = const [], }); final int? id; final DateTime? createdAt; final DateTime? updatedAt; final String? username; final String? psalt; final String? nickname; final String? avatar; final String? qq; final String? email; final String? phone; final String? remark; final int? status; final DeptModel? dept; List roles; factory UserInfoModel.fromJson(Map json) { return UserInfoModel( id: json["id"], createdAt: DateTime.tryParse(json["createdAt"] ?? ""), updatedAt: DateTime.tryParse(json["updatedAt"] ?? ""), username: json["username"], psalt: json["psalt"], nickname: json["nickname"], avatar: json["avatar"], qq: json["qq"], email: json["email"], phone: json["phone"], remark: json["remark"], status: json["status"], dept: json["dept"] == null ? null : DeptModel.fromJson(json["dept"]), roles: json["roles"] == null ? [] : List.from( json["roles"]!.map((x) => RoleModel.fromJson(x))), ); } Map toJson() => { "id": id, "createdAt": createdAt?.toIso8601String(), "updatedAt": updatedAt?.toIso8601String(), "username": username, "psalt": psalt, "nickname": nickname, "avatar": avatar, "qq": qq, "email": email, "phone": phone, "remark": remark, "status": status, "dept": dept?.toJson(), "roles": roles.map((x) => x?.toJson()).toList(), }; }