소스 검색

[feat]键盘插件,登录\退出登录时,刷新键盘数据

hezihao 7 달 전
부모
커밋
03942f47c2

+ 1 - 1
lib/data/consts/constants.dart

@@ -3,7 +3,7 @@ import '../../utils/mmkv_util.dart';
 class Constants {
   Constants._();
 
-  static const String env = envDev;
+  static const String env = envProd;
 
   static const String envDev = 'dev';
 

+ 5 - 0
lib/data/repository/account_repository.dart

@@ -11,6 +11,7 @@ import 'package:keyboard/data/repository/keyboard_repository.dart';
 
 import '../../base/app_base_request.dart';
 import '../../di/get_it.dart';
+import '../../plugins/keyboard_android_platform.dart';
 import '../../utils/async_util.dart';
 import '../../utils/atmob_log.dart';
 import '../../utils/daily_limiter_util.dart';
@@ -204,6 +205,8 @@ class AccountRepository {
     KVUtil.putString(keyAccountLoginPhoneNum, phoneNum);
     KVUtil.putString(keyAccountLoginToken, authToken);
     keyboardRepository.refreshData();
+    // 登录登录,通知键盘刷新数据
+    KeyboardAndroidPlatform.refreshData();
   }
 
   void onWechatLoginSuccess(String authToken) {
@@ -225,6 +228,8 @@ class AccountRepository {
     keyboardRepository.refreshData();
     KVUtil.putString(Constants.keyboardSelect, null);
     DailyLimiterUtil.clearDailyLimitData("SurpriseDialog");
+    // 退出登录,通知键盘刷新数据
+    KeyboardAndroidPlatform.refreshData();
   }
 
   // 意见反馈

+ 5 - 0
lib/plugins/keyboard_android_platform.dart

@@ -106,4 +106,9 @@ class KeyboardAndroidPlatform {
   static void refreshCharacterList() {
     _keyboardAndroidService.refreshCharacterList();
   }
+
+  /// 刷新数据
+  static void refreshData() {
+    _keyboardAndroidService.refreshData();
+  }
 }

+ 4 - 0
lib/plugins/keyboard_android_service.dart

@@ -41,4 +41,8 @@ class KeyboardAndroidService {
   void refreshCharacterList() {
     _plugin.refreshCharacterList();
   }
+
+  void refreshData() {
+    _plugin.refreshData();
+  }
 }

+ 11 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/KeyboardAndroidPlugin.kt

@@ -144,6 +144,17 @@ class KeyboardAndroidPlugin : FlutterPlugin, MethodCallHandler {
                 result.success(null)
             }
 
+            // 登录成功\退出登录\注销账号,刷新用户数据
+            "refreshData" -> {
+                KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.run {
+                    // 刷新数据
+                    getKeyboardList()
+                    getCharacterList()
+                    getPrologueList()
+                    getCurrentKeyboardInfo()
+                }
+            }
+
             else -> {
                 result.notImplemented()
             }

+ 5 - 0
plugins/keyboard_android/lib/keyboard_android.dart

@@ -50,6 +50,11 @@ class KeyboardAndroid {
     KeyboardAndroidPlatform.instance.refreshCharacterList();
   }
 
+  /// 刷新数据
+  void refreshData() {
+    KeyboardAndroidPlatform.instance.refreshData();
+  }
+
   // /// 获取键映射
   // static Future<List<Map<String, String>>> getKeyMappings() {
   //   return KeyboardAndroidPlatform.instance.getKeyMappings();

+ 5 - 0
plugins/keyboard_android/lib/keyboard_android_method_channel.dart

@@ -66,6 +66,11 @@ class MethodChannelKeyboardAndroid extends KeyboardAndroidPlatform {
     methodChannel.invokeMethod('refreshCharacterList');
   }
 
+  @override
+  void refreshData() {
+    methodChannel.invokeMethod('refreshData');
+  }
+
   // /// 获取键映射
   // @override
   // Future<List<Map<String, String>>> getKeyMappings() async {

+ 6 - 6
plugins/keyboard_android/lib/keyboard_android_platform_interface.dart

@@ -28,9 +28,7 @@ abstract class KeyboardAndroidPlatform extends PlatformInterface {
   }
 
   Future<void> initPlugin() {
-    throw UnimplementedError(
-      'initPlugin() has not been implemented.',
-    );
+    throw UnimplementedError('initPlugin() has not been implemented.');
   }
 
   Future<void> enableFloatingWindow(bool enable) {
@@ -64,9 +62,7 @@ abstract class KeyboardAndroidPlatform extends PlatformInterface {
   }
 
   Future<bool> isDefaultKeyboard() {
-    throw UnimplementedError(
-      'isDefaultKeyboard() has not been implemented.',
-    );
+    throw UnimplementedError('isDefaultKeyboard() has not been implemented.');
   }
 
   void updateKeyboardInfo(String keyboardInfoJson) {
@@ -81,6 +77,10 @@ abstract class KeyboardAndroidPlatform extends PlatformInterface {
     );
   }
 
+  void refreshData() {
+    throw UnimplementedError('refreshData() has not been implemented.');
+  }
+
   // /// 获取键映射(需要在 `MethodChannelKeyboardAndroid` 实现)
   // Future<List<Map<String, String>>> getKeyMappings() {
   //   throw UnimplementedError('getKeyMappings() has not been implemented.');

+ 5 - 0
plugins/keyboard_android/test/keyboard_android_test.dart

@@ -54,6 +54,11 @@ class MockKeyboardAndroidPlatform
   void refreshCharacterList() {
     throw UnimplementedError();
   }
+
+  @override
+  void refreshData() {
+    throw UnimplementedError();
+  }
 }
 
 void main() {