|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:doublefeel_flutter/core/config/app_environment_config.dart';
|
|
|
|
import 'package:doublefeel_flutter/pigeon/platform_api.g.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
...
|
...
|
@@ -40,6 +42,26 @@ class UserPreferencesStorage { |
|
|
|
} catch (_) {
|
|
|
|
preferences.value = UserPreferences.empty;
|
|
|
|
}
|
|
|
|
_syncLoginInfoToNative(userInfo: preferences.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _syncLoginInfoToNative(
|
|
|
|
{required UserPreferences userInfo}) async {
|
|
|
|
if (userInfo.accessToken.isEmpty) {
|
|
|
|
try {
|
|
|
|
if (Get.isRegistered<AppEnvironmentConfig>()) {
|
|
|
|
await PlatformHostApi().logout();
|
|
|
|
}
|
|
|
|
} on Exception catch (e) {}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (Get.isRegistered<AppEnvironmentConfig>()) {
|
|
|
|
var env = Get.find<AppEnvironmentConfig>();
|
|
|
|
await PlatformHostApi()
|
|
|
|
.updateLoginInfo(jsonEncode(userInfo), env.serverBaseUrl);
|
|
|
|
}
|
|
|
|
} on Exception catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _persist(UserPreferences value) async {
|
...
|
...
|
|