Showing
1 changed file
with
22 additions
and
0 deletions
| 1 | import 'dart:convert'; | 1 | import 'dart:convert'; |
| 2 | 2 | ||
| 3 | +import 'package:doublefeel_flutter/core/config/app_environment_config.dart'; | ||
| 4 | +import 'package:doublefeel_flutter/pigeon/platform_api.g.dart'; | ||
| 3 | import 'package:get/get.dart'; | 5 | import 'package:get/get.dart'; |
| 4 | import 'package:shared_preferences/shared_preferences.dart'; | 6 | import 'package:shared_preferences/shared_preferences.dart'; |
| 5 | 7 | ||
| @@ -40,6 +42,26 @@ class UserPreferencesStorage { | @@ -40,6 +42,26 @@ class UserPreferencesStorage { | ||
| 40 | } catch (_) { | 42 | } catch (_) { |
| 41 | preferences.value = UserPreferences.empty; | 43 | preferences.value = UserPreferences.empty; |
| 42 | } | 44 | } |
| 45 | + _syncLoginInfoToNative(userInfo: preferences.value); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + Future<void> _syncLoginInfoToNative( | ||
| 49 | + {required UserPreferences userInfo}) async { | ||
| 50 | + if (userInfo.accessToken.isEmpty) { | ||
| 51 | + try { | ||
| 52 | + if (Get.isRegistered<AppEnvironmentConfig>()) { | ||
| 53 | + await PlatformHostApi().logout(); | ||
| 54 | + } | ||
| 55 | + } on Exception catch (e) {} | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + try { | ||
| 59 | + if (Get.isRegistered<AppEnvironmentConfig>()) { | ||
| 60 | + var env = Get.find<AppEnvironmentConfig>(); | ||
| 61 | + await PlatformHostApi() | ||
| 62 | + .updateLoginInfo(jsonEncode(userInfo), env.serverBaseUrl); | ||
| 63 | + } | ||
| 64 | + } on Exception catch (e) {} | ||
| 43 | } | 65 | } |
| 44 | 66 | ||
| 45 | Future<void> _persist(UserPreferences value) async { | 67 | Future<void> _persist(UserPreferences value) async { |
-
Please register or login to post a comment