1
This commit is contained in:
@@ -7,21 +7,17 @@ class UserStore extends ChangeNotifier {
|
||||
UserInfoDto? userInfo;
|
||||
String token = "";
|
||||
|
||||
///设置用户数据
|
||||
Future<void> asyncUserInfo() async {
|
||||
if (token.isNotEmpty) {
|
||||
var res = await getUserInfoApi();
|
||||
await Storage.set("user_info", res.toJson());
|
||||
setUserInfo();
|
||||
notifyListeners();
|
||||
}
|
||||
Future<void> init() async{
|
||||
token = await getToken();
|
||||
await setUserInfo();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///获取用户数据
|
||||
Future<void> setUserInfo() async {
|
||||
var info = await Storage.get("user_info");
|
||||
if (info != null) {
|
||||
userInfo = UserInfoDto.fromJson(info);
|
||||
if (token.isNotEmpty) {
|
||||
userInfo = await getUserInfoApi();
|
||||
await Storage.set("user_info", userInfo!.toJson());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +28,16 @@ class UserStore extends ChangeNotifier {
|
||||
}
|
||||
|
||||
///获取token
|
||||
static Future<String> getToken() async {
|
||||
static Future<String> getToken() async {
|
||||
return await Storage.get("token") ?? '';
|
||||
}
|
||||
|
||||
///退出登录
|
||||
Future<void> logout() async {
|
||||
logoutApi();
|
||||
await logoutApi();
|
||||
await Storage.remove('token');
|
||||
await Storage.remove('user_info');
|
||||
userInfo = null;
|
||||
token = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user