fix: fix storage of selected language not working on mobile (#4334)

This commit is contained in:
ggurdin 2025-10-10 15:11:24 -04:00 committed by GitHub
parent c4ff6b0ac4
commit 453338da01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 21 deletions

View file

@ -48,9 +48,10 @@ class CreatePangeaAccountPageState extends State<CreatePangeaAccountPage> {
String? _spaceId;
String? _courseLangCode;
String? get _cachedLangCode => LangCodeRepo.get();
Future<String?> get _cachedLangCode => LangCodeRepo.get();
String? get _langCode => _courseLangCode ?? _cachedLangCode;
Future<String?> get _langCode async =>
_courseLangCode ?? (await _cachedLangCode);
String? get _cachedSpaceCode =>
MatrixState.pangeaController.spaceCodeController.cachedSpaceCode;
@ -131,10 +132,10 @@ class CreatePangeaAccountPageState extends State<CreatePangeaAccountPage> {
}
Future<void> _updateTargetLanguage() async {
if (_langCode == null) return;
final langCode = await _langCode;
await MatrixState.pangeaController.userController.updateProfile(
(profile) {
profile.userSettings.targetLanguage = _langCode;
profile.userSettings.targetLanguage = langCode;
return profile;
},
waitForDataInSync: true,
@ -150,15 +151,7 @@ class CreatePangeaAccountPageState extends State<CreatePangeaAccountPage> {
}
try {
if (_langCode == null) {
// at this point, there's no cached selected language, and couldn't get
// language from cached course code, so go back to the language selection page
if (mounted) {
context.go('/registration');
}
return;
}
final langCode = await _langCode;
final updateFuture = [
_setAvatar(),
MatrixState.pangeaController.userController.updateProfile(
@ -170,18 +163,19 @@ class CreatePangeaAccountPageState extends State<CreatePangeaAccountPage> {
profile.userSettings.sourceLanguage = systemLang;
}
profile.userSettings.targetLanguage = _langCode;
profile.userSettings.targetLanguage = langCode;
profile.userSettings.createdAt = DateTime.now();
return profile;
},
waitForDataInSync: true,
),
MatrixState.pangeaController.userController.updateAnalyticsProfile(
targetLanguage: PLanguageStore.byLangCode(_langCode!),
baseLanguage:
MatrixState.pangeaController.languageController.systemLanguage,
level: 1,
),
if (langCode != null)
MatrixState.pangeaController.userController.updateAnalyticsProfile(
targetLanguage: PLanguageStore.byLangCode(langCode),
baseLanguage:
MatrixState.pangeaController.languageController.systemLanguage,
level: 1,
),
];
await Future.wait(updateFuture).timeout(

View file

@ -3,15 +3,22 @@ import 'package:get_storage/get_storage.dart';
class LangCodeRepo {
static final GetStorage _storage = GetStorage('lang_code_storage');
static String? get() {
static Future<void> _init() async {
await GetStorage.init('lang_code_storage');
}
static Future<String?> get() async {
await _init();
return _storage.read('lang_code');
}
static Future<void> set(String langcode) async {
await _init();
await _storage.write('lang_code', langcode);
}
static Future<void> remove() async {
await _init();
await _storage.remove('lang_code');
}
}