I have an app which supports Swedish and English, and they show up as selectable languages in the iOS settings screen for my app. But when the app starts, I never get "sv" as selected locale if the users main language is something other than Swedish or English, so it's as if I never get the selected app language, but only the main OS langauge.
If the user does have English or Swedish as their main OS language, and they set Swedish as the language for the app, I get the correct reading of the app language, but I can STILL not get easy_localization to set that language. In my MaterialApp context.locale still doesn't get set to the correct one. So if the user's main langague is English, but they set the app lang to Swedish, in my main function I will se "sv_SE" (correct), but then in MyApp, context.locale is set to "en" still.
This is my main function and my MaterialApp:
Future<void> main() async {
runZonedGuarded<Future<void>>(() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
Locale currentLocaleForApp = WidgetsBinding.instance.platformDispatcher.locale; // <- This only gets set to "sv" if the OS main locale is either Swedish or English, otherwise it becomes the main OS locale and will default to "en" regardless what they selected for the app.
runApp(ProviderScope(
child: EasyLocalization(
key: UniqueKey(),
supportedLocales: [const Locale('sv'), const Locale('en')],
path: 'assets/translations',
fallbackLocale: Locale('en'),
useOnlyLangCode: true,
child: MyApp())));
}, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack));
}
...
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: ResponsiveSizer(
builder: (context, orientation, screenType) {
return MaterialApp(
locale: context.locale, // <- This never changes to "sv" unless main OS is Swedish
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
onGenerateTitle: (context) {
return "My app name";
},
theme: ThemeData(
splashColor: Colors.transparent,
visualDensity: VisualDensity.adaptivePlatformDensity,
primarySwatch: BirdsTheme.CompanyColors.primary,
fontFamily: 'Poppins'),
navigatorKey: _navigationService.navigatorKey,
onGenerateRoute: generateRoute,
home: child);
},
));
What am I missing here? It seems like I'm only able to read the main OS language, but not the language set specifically for the app in iOS. Am I reading the selected locale wrong?