|
|
@@ -11,7 +11,11 @@ import 'package:zhiying_comm/util/shared_prefe_util.dart'; |
|
|
|
/// |
|
|
|
class UserInfoNotifier with ChangeNotifier { |
|
|
|
/// 用户信息 |
|
|
|
UserInfoModel _userInfo; |
|
|
|
static UserInfoModel _userInfo; |
|
|
|
|
|
|
|
static UserInfoModel get staitcUserInfo { |
|
|
|
return _userInfo; |
|
|
|
} |
|
|
|
|
|
|
|
UserInfoModel get userInfo { |
|
|
|
if (null == _userInfo) { |
|
|
@@ -28,7 +32,7 @@ class UserInfoNotifier with ChangeNotifier { |
|
|
|
/// 更新用户数据 |
|
|
|
void setUserInfo(UserInfoModel loginUser) async { |
|
|
|
print('${loginUser.toString()}'); |
|
|
|
this._userInfo = loginUser; |
|
|
|
_userInfo = loginUser; |
|
|
|
// 缓存数据 |
|
|
|
await SharedPreferencesUtil.setStringValue( |
|
|
|
GlobalConfig.SHARED_KEY_TOKEN, loginUser.token); |
|
|
@@ -41,7 +45,7 @@ class UserInfoNotifier with ChangeNotifier { |
|
|
|
|
|
|
|
/// 退出登陆 |
|
|
|
void unLogin() async { |
|
|
|
this._userInfo = null; |
|
|
|
_userInfo = null; |
|
|
|
// 清除缓存数据 |
|
|
|
await SharedPreferencesUtil.setStringValue( |
|
|
|
GlobalConfig.SHARED_KEY_TOKEN, ''); |
|
|
@@ -60,7 +64,11 @@ class UserInfoNotifier with ChangeNotifier { |
|
|
|
try { |
|
|
|
String userInfoJson = await SharedPreferencesUtil.getStringValue( |
|
|
|
GlobalConfig.SHARED_KEY_USER_INFO); |
|
|
|
_userInfo = UserInfoModel.fromJson(jsonDecode(userInfoJson)); |
|
|
|
if (userInfoJson == null || userInfoJson == '') { |
|
|
|
_userInfo = UserInfoModel(); |
|
|
|
} else { |
|
|
|
_userInfo = UserInfoModel.fromJson(jsonDecode(userInfoJson)); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
Logger.log(e); |
|
|
|
} |
|
|
|