|
@@ -1,5 +1,6 @@
|
|
|
import 'dart:convert';
|
|
|
|
|
|
+import 'package:shuqi/model/user_model.dart';
|
|
|
import 'package:shuqi/utility/event_bus.dart';
|
|
|
import 'package:shuqi/model/constant.dart';
|
|
|
|
|
@@ -9,8 +10,8 @@ const String EventUserLogout = 'EventUserLogout';
|
|
|
class UserManager {
|
|
|
static UserManager instance = UserManager();
|
|
|
|
|
|
- User? user;
|
|
|
- static User? get currentUser {
|
|
|
+ UserModel? user;
|
|
|
+ static UserModel? get currentUser {
|
|
|
return UserManager.instance.user;
|
|
|
}
|
|
|
|
|
@@ -21,7 +22,7 @@ class UserManager {
|
|
|
}
|
|
|
|
|
|
login(Map<String, dynamic> userJson) {
|
|
|
- var user = User.fromJson(userJson);
|
|
|
+ var user = UserModel.fromJson(userJson);
|
|
|
this.user = user;
|
|
|
saveUser();
|
|
|
|
|
@@ -35,7 +36,7 @@ class UserManager {
|
|
|
loadUserFromLocal() {
|
|
|
String? userJson = preferences.getString('user');
|
|
|
if (userJson != null) {
|
|
|
- user = User.fromJson(json.decode(userJson));
|
|
|
+ user = UserModel.fromJson(json.decode(userJson));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -45,37 +46,3 @@ class UserManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class User {
|
|
|
- late String token;
|
|
|
- late int id;
|
|
|
- late String nickname;
|
|
|
- late String avatarUrl;
|
|
|
- late bool isVip;
|
|
|
- late double wealth;
|
|
|
- late int coupon;
|
|
|
- late int monthlyTicket;
|
|
|
-
|
|
|
- User.fromJson(Map json) {
|
|
|
- token = json['token'];
|
|
|
- id = json['id'];
|
|
|
- nickname = json['nickname'];
|
|
|
- avatarUrl = json['avatar'];
|
|
|
- isVip = json['is_vip'] == 1;
|
|
|
- wealth = json['wealth'];
|
|
|
- coupon = json['coupon'];
|
|
|
- monthlyTicket = json['ticket'];
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, dynamic> toJson() {
|
|
|
- return {
|
|
|
- 'token': token,
|
|
|
- 'id': id,
|
|
|
- 'nickname': nickname,
|
|
|
- 'avatar': avatarUrl,
|
|
|
- 'is_vip': isVip ? 1 : 0,
|
|
|
- 'wealth': wealth,
|
|
|
- 'coupon': coupon,
|
|
|
- 'ticket': monthlyTicket,
|
|
|
- };
|
|
|
- }
|
|
|
-}
|