You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TimeManager/src/timemanagerapp/lib/entity/User.dart

82 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

class User {
int? id;
int teamId;
String username;
String password;
int role; //0表示一般用户1表示管理员
User({
this.id,
required this.teamId,
required this.username,
required this.password,
required this.role,
});
Map<String, dynamic> toMap() {
return {
'teamId': teamId,
'username': "$username",
'password': "$password",
'role': role,
};
}
// Getter methods
int? get getId => id;
int get getTeamId => teamId;
String get getUsername => username;
String get getPassword => password;
int get getRole => role;
// Setter methods
set setId(int newId) {
id = newId;
}
set setTeamId(int newTeamId) {
teamId = newTeamId;
}
set setUsername(String newUsername) {
username = newUsername;
}
set setPassword(String newPassword) {
password = newPassword;
}
set setRole(int newRole) {
role = newRole;
}
// 构造一个 User 对象的工厂方法
factory User.parseString(String userString) {
final parts = userString.split(', '); // 根据 toString() 生成的格式分割字符串
final id = int.parse(parts[0].substring(8)); // 提取并解析 id
final teamId = int.parse(parts[1].substring(7)); // 提取并解析 teamId
final username = parts[2].substring(10); // 提取用户名
final password = parts[3].substring(10); // 提取密码
final role = int.parse(parts[4].substring(6)); // 提取并解析 role
return User(
id: id,
teamId: teamId,
username: username,
password: password,
role: role,
);
}
// toString method
@override
String toString() {
return 'User(id: $id, teamId:$teamId, username: $username, password: $password, role: $role)';
}
}