|
|
@@ -27,7 +27,7 @@ class AccountRepository {
|
|
|
final ACCOUNT_TOKEN = 'account_token';
|
|
|
final ACCOUNT_PHONE = 'account_phone';
|
|
|
|
|
|
- String? _token;
|
|
|
+ static String? token;
|
|
|
String? _phone;
|
|
|
final isLogin = false.obs;
|
|
|
|
|
|
@@ -37,14 +37,14 @@ class AccountRepository {
|
|
|
|
|
|
AccountRepository._() {
|
|
|
debugPrint('AccountRepository init');
|
|
|
- _token = KVUtil.getString(ACCOUNT_TOKEN, null);
|
|
|
+ token = KVUtil.getString(ACCOUNT_TOKEN, null);
|
|
|
_phone = KVUtil.getString(ACCOUNT_PHONE, null);
|
|
|
- if (_token != null && _token!.isNotEmpty) {
|
|
|
+
|
|
|
+ refreshUserInfo();
|
|
|
+
|
|
|
+ if (token != null && token!.isNotEmpty) {
|
|
|
isLogin.value = true;
|
|
|
- Future.delayed(Duration.zero, () {
|
|
|
- refreshUserInfo();
|
|
|
- taskRepository.startUnfinishedTask();
|
|
|
- });
|
|
|
+ taskRepository.startUnfinishedTask();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -52,8 +52,6 @@ class AccountRepository {
|
|
|
|
|
|
String? get phone => _phone;
|
|
|
|
|
|
- String? get token => _token;
|
|
|
-
|
|
|
Future<void> getVerificationCode(String phone) {
|
|
|
return atmobApi
|
|
|
.getVerificationCode(VerificationCodeRequest(phone))
|
|
|
@@ -96,6 +94,8 @@ class AccountRepository {
|
|
|
.then((response) {
|
|
|
if (response.loginStatus == 0) {
|
|
|
logout();
|
|
|
+ } else {
|
|
|
+ isLogin.value = true;
|
|
|
}
|
|
|
_userInfo.value = response;
|
|
|
return response;
|
|
|
@@ -119,7 +119,7 @@ class AccountRepository {
|
|
|
}
|
|
|
|
|
|
void onLoginSuccess(String phone, String? token) {
|
|
|
- _token = token;
|
|
|
+ AccountRepository.token = token;
|
|
|
_phone = phone;
|
|
|
KVUtil.putString(ACCOUNT_TOKEN, token);
|
|
|
KVUtil.putString(ACCOUNT_PHONE, phone);
|
|
|
@@ -133,7 +133,7 @@ class AccountRepository {
|
|
|
|
|
|
void logout() {
|
|
|
_phone = null;
|
|
|
- _token = null;
|
|
|
+ AccountRepository.token = null;
|
|
|
KVUtil.putString(ACCOUNT_TOKEN, null);
|
|
|
KVUtil.putString(ACCOUNT_PHONE, null);
|
|
|
isLogin.value = false;
|