Skip to content

Commit 08d4182

Browse files
author
RockerFlower
committed
🌐 Keep the language pref
1 parent 733956e commit 08d4182

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

lib/main.dart

+20-5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ class MyApp extends StatelessWidget {
159159
}
160160
}
161161

162+
Locale _getLocale() {
163+
Box box = Hive.box(prefBox);
164+
var languagePref = box.get(prefLanguageKey);
165+
Locale locale = const Locale(
166+
'en',
167+
'US',
168+
);
169+
if (languagePref != null) {
170+
List localeString = languagePref.split('_');
171+
if (localeString.length == 2) {
172+
locale = Locale(localeString[0], localeString[1]);
173+
} else if (localeString.length == 1) {
174+
locale = Locale(localeString[0], '');
175+
}
176+
}
177+
return locale;
178+
}
179+
162180
@override
163181
Widget build(BuildContext context) {
164182
return GetMaterialApp(
@@ -173,13 +191,10 @@ class MyApp extends StatelessWidget {
173191
unknownRoute: AppPages.unknownRoute,
174192
defaultTransition: kIsWeb ? Transition.topLevel : Transition.native,
175193
translations: LocaleString(), // Translations
176-
locale: const Locale(
177-
'en',
178-
'US',
179-
), // translations will be displayed in that locale
194+
locale: _getLocale(), // translations will be displayed in that locale
180195
fallbackLocale: const Locale(
181196
'en',
182-
'UK',
197+
'US',
183198
), // specify the fallback locale in case an invalid locale is selected.
184199
title: 'POAPin',
185200
theme: ThemeData(

0 commit comments

Comments
 (0)