Explorar el Código

[new]调整account仓库代码

zk hace 8 meses
padre
commit
25c8b76633
Se han modificado 3 ficheros con 13 adiciones y 13 borrados
  1. 1 1
      lib/base/app_base_request.dart
  2. 11 11
      lib/data/repositories/account_repository.dart
  3. 1 1
      pubspec.yaml

+ 1 - 1
lib/base/app_base_request.dart

@@ -7,7 +7,7 @@ part 'app_base_request.g.dart';
 @JsonSerializable()
 class AppBaseRequest extends BaseRequest {
   @JsonKey(name: 'authToken')
-  String? authToken = accountRepository.token;
+  String? authToken = AccountRepository.token;
 
   @override
   Map<String, dynamic> toJson() => _$AppBaseRequestToJson(this);

+ 11 - 11
lib/data/repositories/account_repository.dart

@@ -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;

+ 1 - 1
pubspec.yaml

@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 # In Windows, build-name is used as the major, minor, and patch parts
 # of the product and file versions while build-number is used as the build suffix.
-version: 1.1.1+111
+version: 1.1.2+112
 
 
 environment: