fix: brazillian localle bug that makes app unresponsive

This commit is contained in:
Blazebrain
2026-09-03 13:40:26 +01:00
parent 73a739411f
commit 3fabbc5c5e
3 changed files with 26 additions and 5 deletions
+13
View File
@@ -1,7 +1,20 @@
import 'package:cake_wallet/generated/locales.dart';
import 'package:devicelocale/devicelocale.dart';
import "package:flutter/widgets.dart";
import 'package:intl/intl.dart';
// This will turn stored language code into Flutter Locale.
// Some of our language codes uses an underscore (like "pt_BR") and this must be split into language
// and country subtags, if we pass the whole string as the languageCode, GlobalMaterialLocalizations
// would reject it as an invalid ISO 639-1 code and crash the app on locale switch
Locale localeFromLanguageCode(String code) {
final parts = code.split("_");
if (parts.length == 2 && parts[0].isNotEmpty && parts[1].isNotEmpty) {
return Locale(parts[0], parts[1]);
}
return Locale(code);
}
class LanguageService {
static const Map<String, String> supportedLocales = {
'en': 'English',
+1 -1
View File
@@ -426,7 +426,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
themeMode: themeMode,
localizationsDelegates: localizationDelegates,
supportedLocales: S.delegate.supportedLocales,
locale: Locale(appStore.settingsStore.languageCode),
locale: localeFromLanguageCode(appStore.settingsStore.languageCode),
onGenerateRoute: (settings) => Router.createRoute(settings),
initialRoute: initialRoute,
scrollBehavior: AppScrollBehavior(),