'Flutter - How to force flutter_localizations to the desired lang?
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!
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JC Junior |
