2023-07-11 23:39:36 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-04-09 17:23:28 +08:00
|
|
|
import '/utils/app_dir.dart';
|
2023-07-11 23:39:36 +08:00
|
|
|
|
|
|
|
class UserAccount extends ChangeNotifier {
|
|
|
|
String id = '';
|
|
|
|
String username = '';
|
|
|
|
String email = '';
|
|
|
|
|
2023-07-27 18:17:52 +08:00
|
|
|
void init(Map<String, dynamic> data) {
|
2023-07-11 23:39:36 +08:00
|
|
|
id = data['id']!;
|
|
|
|
username = data['username']!;
|
|
|
|
email = data['email']!;
|
|
|
|
}
|
2023-07-17 01:00:16 +08:00
|
|
|
|
2023-08-11 23:02:31 +08:00
|
|
|
Map<String, String> toMap() {
|
|
|
|
return {
|
|
|
|
'id': id,
|
|
|
|
'username': username,
|
|
|
|
'email': email,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-17 01:00:16 +08:00
|
|
|
void updateUsername(String newUsername) {
|
|
|
|
username = newUsername;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateEmail(String newEmail) {
|
|
|
|
email = newEmail;
|
|
|
|
}
|
2023-07-27 18:17:52 +08:00
|
|
|
|
2023-09-09 16:48:47 +08:00
|
|
|
void clear() {
|
2023-07-27 18:17:52 +08:00
|
|
|
id = '';
|
|
|
|
username = '';
|
|
|
|
email = '';
|
|
|
|
}
|
2023-07-11 23:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class UserProfile extends ChangeNotifier {
|
|
|
|
String nickname = '';
|
|
|
|
String gender = '';
|
|
|
|
String birthday = '';
|
|
|
|
String location = '';
|
|
|
|
String status = '';
|
|
|
|
String sign = '';
|
|
|
|
String avatar = '';
|
2023-08-15 10:53:30 +08:00
|
|
|
String baseImageDir = '';
|
2023-07-11 23:39:36 +08:00
|
|
|
bool isInitialised = false;
|
|
|
|
|
2023-07-27 18:17:52 +08:00
|
|
|
Future<void> init(Map<String, dynamic> json) async {
|
|
|
|
nickname = json['nickname'] ?? '';
|
|
|
|
birthday = json['birthday'] ?? '';
|
|
|
|
location = json['location'] ?? '';
|
|
|
|
status = json['status'] ?? '';
|
|
|
|
sign = json['sign'] ?? '';
|
2023-08-01 10:01:08 +08:00
|
|
|
avatar = json['avatar'] ?? '';
|
2023-08-15 10:53:30 +08:00
|
|
|
baseImageDir = await getChatImageDir();
|
2023-07-27 18:17:52 +08:00
|
|
|
gender = _genderEn2Cn(json['gender'] ?? '');
|
2023-07-11 23:39:36 +08:00
|
|
|
isInitialised = true;
|
|
|
|
}
|
|
|
|
|
2023-08-11 23:02:31 +08:00
|
|
|
Map<String, String> toMap() {
|
|
|
|
return {
|
|
|
|
'nickname': nickname,
|
|
|
|
'gender': gender,
|
|
|
|
'birthday': birthday,
|
|
|
|
'location': location,
|
|
|
|
'status': status,
|
|
|
|
'sign': sign,
|
|
|
|
'avatar': avatar,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-21 21:25:09 +08:00
|
|
|
Map<String, String> toMapCn() {
|
|
|
|
return {
|
|
|
|
'签名': sign,
|
|
|
|
'状态': status,
|
|
|
|
'名字': nickname,
|
|
|
|
'生日': birthday.isNotEmpty
|
|
|
|
? '${birthday.substring(0, 4)}年${birthday.substring(5, 7)}月${birthday.substring(8)}日'
|
|
|
|
: '',
|
|
|
|
'位置': location,
|
|
|
|
'性别': gender,
|
|
|
|
};
|
2023-07-11 23:39:36 +08:00
|
|
|
}
|
|
|
|
|
2023-10-21 21:25:09 +08:00
|
|
|
void changeBasic(
|
|
|
|
String newSign,
|
|
|
|
String newStatus,
|
|
|
|
String newNickname,
|
|
|
|
String newBirthday,
|
|
|
|
String newLocation,
|
|
|
|
String newGender,
|
|
|
|
) {
|
2023-07-11 23:39:36 +08:00
|
|
|
sign = newSign;
|
2023-10-06 16:43:51 +08:00
|
|
|
status = newStatus;
|
2023-10-21 21:25:09 +08:00
|
|
|
nickname = newNickname;
|
|
|
|
birthday = newBirthday;
|
|
|
|
location = newLocation;
|
|
|
|
gender = newGender;
|
2023-10-06 16:43:51 +08:00
|
|
|
}
|
|
|
|
|
2023-10-21 21:25:09 +08:00
|
|
|
void changeAvatar(String newAvatar) async {
|
2023-08-01 10:01:08 +08:00
|
|
|
avatar = newAvatar;
|
2023-07-11 23:39:36 +08:00
|
|
|
}
|
|
|
|
|
2023-09-09 16:48:47 +08:00
|
|
|
void clear() {
|
2023-07-27 18:17:52 +08:00
|
|
|
nickname = '';
|
|
|
|
gender = '';
|
|
|
|
birthday = '';
|
|
|
|
location = '';
|
|
|
|
status = '';
|
|
|
|
sign = '';
|
|
|
|
avatar = '';
|
2023-08-15 10:53:30 +08:00
|
|
|
baseImageDir = '';
|
2023-07-27 18:17:52 +08:00
|
|
|
isInitialised = false;
|
|
|
|
}
|
|
|
|
|
2023-07-11 23:39:36 +08:00
|
|
|
String _genderEn2Cn(String newGender) {
|
|
|
|
if (newGender.isEmpty) {
|
|
|
|
return newGender;
|
|
|
|
} else {
|
|
|
|
return newGender == 'man' ? '男' : '女';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|