Files
plan_flutter/lib/api/dto/login_dto.dart
zhutao 0231dcfe1a 1
2025-09-04 17:57:35 +08:00

91 lines
1.9 KiB
Dart

class UserInfo {
int? id;
String? name;
String? avatar;
String? description;
String? email;
String? googleId;
String? appleId;
int? status;
UserInfo({
this.id,
this.name,
this.avatar,
this.description,
this.email,
this.googleId,
this.appleId,
this.status,
});
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map["id"] = id;
map["name"] = name;
map["avatar"] = avatar;
map["description"] = description;
map["email"] = email;
map["google_id"] = googleId;
map["apple_id"] = appleId;
map["status"] = status;
return map;
}
UserInfo.fromJson(dynamic json) {
id = json["id"] ?? 0;
name = json["name"] ?? "";
avatar = json["avatar"];
description = json["description"] ?? "";
email = json["email"] ?? "";
googleId = json["google_id"];
appleId = json["apple_id"];
status = json["status"] ?? 0;
}
/// copyWith 方法
UserInfo copyWith({
int? id,
String? name,
String? avatar,
String? description,
String? email,
String? googleId,
String? appleId,
int? status,
}) {
return UserInfo(
id: id ?? this.id,
name: name ?? this.name,
avatar: avatar ?? this.avatar,
description: description ?? this.description,
email: email ?? this.email,
googleId: googleId ?? this.googleId,
appleId: appleId ?? this.appleId,
status: status ?? this.status,
);
}
}
class LoginDto {
String? accessToken;
UserInfo? userInfo;
LoginDto({this.accessToken, this.userInfo});
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map["accessToken"] = accessToken;
if (userInfo != null) {
map["userInfo"] = userInfo?.toJson();
}
return map;
}
LoginDto.fromJson(dynamic json) {
accessToken = json["accessToken"] ?? "";
userInfo = json["userInfo"] != null ? UserInfo.fromJson(json["userInfo"]) : null;
}
}