Flutter - How to force flutter_localizations to the desired lang?

781 views Asked by At

I have integrated flutter localizations dependent of system language, works very well. But I want to "force" language programmatically, without matters on system language.

My app root:

return GetMaterialApp(
      localizationsDelegates: const [
        AppLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('sr', ''),
        Locale('en', ''),
      ],

My lang config file:

arb-dir: lib/l10n
template-arb-file: app_sr.arb
output-localization-file: app_localizations.dart

Any every next new entering into the app will "keep" the user choose preferred language. Thank you!

1

There are 1 answers

1
JC Junior On

You can add the locale attribute to your MaterialApp, like that:

// Content from your MaterialApp

locale: const Locale('sr'),

// More content from your MaterialApp

If you need change in another part of your app, you can change de Locale in your AppLocalizations class.