Commit d13cd4c8e3e73bc050aaaa0b32c981418253e272

Authored by 权海
1 parent 57c728d2

feat(ui):登录进入app前向原生同步信息的部分代码不用await

(cherry picked from commit 71aab30e)

# Conflicts:
#	lib/app/bootstrap/app_bootstrap.dart
@@ -44,7 +44,11 @@ abstract final class AppBootstrap { @@ -44,7 +44,11 @@ abstract final class AppBootstrap {
44 localStorage: local, 44 localStorage: local,
45 ).dependencies(); 45 ).dependencies();
46 46
47 - await userPreferencesStorage.syncLoginInfoToNative(); 47 + // `UserPreferencesStorage.init` runs before GetX dependencies exist. Sync
  48 + // here so every cold start invokes native `updateLoginInfo` after the
  49 + // PlatformHostApi and HealthRawDataCoreService are ready.
  50 + unawaited(userPreferencesStorage.syncLoginInfoToNative());
  51 +
48 NativeHealthDataUpdateBridge.initialize(); 52 NativeHealthDataUpdateBridge.initialize();
49 53
50 LoadingService.init(); 54 LoadingService.init();
@@ -84,6 +88,8 @@ abstract final class AppBootstrap { @@ -84,6 +88,8 @@ abstract final class AppBootstrap {
84 localStorage: local, 88 localStorage: local,
85 ).dependencies(); 89 ).dependencies();
86 90
  91 + unawaited(userPreferencesStorage.syncLoginInfoToNative());
  92 +
87 NativeHealthDataUpdateBridge.initialize(); 93 NativeHealthDataUpdateBridge.initialize();
88 // 2. 后台无 UI,不需要初始化全局 Loading 弹窗 94 // 2. 后台无 UI,不需要初始化全局 Loading 弹窗
89 LoadingService.init(); 95 LoadingService.init();
@@ -631,7 +631,9 @@ class LoginController extends GetxController { @@ -631,7 +631,9 @@ class LoginController extends GetxController {
631 try { 631 try {
632 if (Get.isRegistered<AppEnvironmentConfig>()) { 632 if (Get.isRegistered<AppEnvironmentConfig>()) {
633 var env = Get.find<AppEnvironmentConfig>(); 633 var env = Get.find<AppEnvironmentConfig>();
634 - await AppPlatformHostApi().updateLoginInfo( 634 + unawaited(
  635 + AppPlatformHostApi()
  636 + .updateLoginInfo(
635 jsonEncode(UserPreferences( 637 jsonEncode(UserPreferences(
636 accessToken: accessToken, 638 accessToken: accessToken,
637 meUserInfo: me, 639 meUserInfo: me,
@@ -640,7 +642,12 @@ class LoginController extends GetxController { @@ -640,7 +642,12 @@ class LoginController extends GetxController {
640 ? UserPreferencesVipInfo.fromVipInfo(vip) 642 ? UserPreferencesVipInfo.fromVipInfo(vip)
641 : null, 643 : null,
642 )), 644 )),
643 - env.serverBaseUrl); 645 + env.serverBaseUrl,
  646 + )
  647 + .catchError((Object error, StackTrace stackTrace) {
  648 + AppLogger.e('Native login info sync failed', error, stackTrace);
  649 + }),
  650 + );
644 } 651 }
645 } on Exception catch (e) { 652 } on Exception catch (e) {
646 AppLogger.e(e); 653 AppLogger.e(e);
  1 +import 'dart:async';
1 import 'dart:convert'; 2 import 'dart:convert';
2 3
3 import 'package:doublefeel_flutter/core/config/app_environment_config.dart'; 4 import 'package:doublefeel_flutter/core/config/app_environment_config.dart';
@@ -143,7 +144,9 @@ class UserPreferencesStorage { @@ -143,7 +144,9 @@ class UserPreferencesStorage {
143 vipInfo: vip != null ? UserPreferencesVipInfo.fromVipInfo(vip) : null, 144 vipInfo: vip != null ? UserPreferencesVipInfo.fromVipInfo(vip) : null,
144 ); 145 );
145 await _persist(userInfo); 146 await _persist(userInfo);
146 - await _syncLoginInfoToNative(userInfo: userInfo); 147 + // Native login/health database synchronization is best effort and can
  148 + // trigger expensive platform work. Do not hold the login transition for it.
  149 + unawaited(_syncLoginInfoToNative(userInfo: userInfo));
147 } 150 }
148 151
149 Future<void> clearPartnerUserInfo() async { 152 Future<void> clearPartnerUserInfo() async {