Hi,
There is a set language page in my app
I am setting the locale when the language is changed.
This is where I am setting the locale :
```class LanguagePage extends StatefulWidget {
LanguagePage({Key key}) : super(key: key);
@override
_LanguagePageState createState() => _LanguagePageState();
}
class _LanguagePageState extends State
String selectedLanguage;
bool shouldTranslateEntireApp = false;
Future whenDoneIsPressed() async {
BlocProvider.of
.add(LanguageUpdating(language: selectedLanguage, shouldTranslateEntireApp: shouldTranslateEntireApp));
}
@override
void initState() {
BlocProvider.of
super.initState();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: BlocConsumer
if (state is LanguageInitial) {
setState(() {
shouldTranslateEntireApp = state.enableSystemWide;
selectedLanguage = state.selectedLanguage;
});
}
if (state is LanguageUpdated) {
if (state.enableSystemWide == true) {
var codes = languagesTextAndCode[state.selectedLanguage].split("-");
EasyLocalization.of(context).locale = Locale(codes.first, codes.last);
// data.changeLocale(
// locale: Locale(codes.first, codes.last));
}
if (state.isLoggedIn == true) {
Navigator.of(context).pop();
} else {
await Navigator.of(context).pushReplacementNamed(Routes.onBoarding);
}
}
}, builder: (context, state) {
var languages = {};
if (state is LanguageInitial) {
languages = state.languages;
}
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Text(
StringRes.appName,
textAlign: TextAlign.center,
style: Helper.contentStyle(language: 'k', fontSize: 36).copyWith(color: Theme.of(context).accentColor),
).tr(),
),
Text(
'Choose your language to continue',
textAlign: TextAlign.center,
),
SizedBox(height: 16),
Expanded(
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(16),
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: 3 / 1,
crossAxisCount: 2,
children: <Widget>[
...(languages).entries.map((entry) {
var language = entry.key;
return LanguageButton(
language: entry.value,
selected: selectedLanguage == language,
onTap: () {
setState(() => selectedLanguage = language);
});
})
],
),
),
SizedBox(height: 16),
Row(
children: <Widget>[
SizedBox(
width: 20,
),
Icon(Icons.public),
SizedBox(width: 4),
Expanded(child: Text(StringRes.translateApp).tr()),
Checkbox(
value: shouldTranslateEntireApp,
onChanged: (check) => setState(() => shouldTranslateEntireApp = check),
),
],
),
SizedBox(height: 10),
FractionallySizedBox(
widthFactor: 0.5,
child: RaisedButton(
onPressed: whenDoneIsPressed,
child: Text("Done"),
),
),
SizedBox(height: 10),
],
);
}),
),
);
}
}
This is where I am getting the locale in main.dart
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
EasyLocalization.of(context).delegate,
],
supportedLocales: EasyLocalization.of(context).supportedLocales,
locale:
EasyLocalization.of(context).locale, // navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
theme: state.isDark == true
? Theme.darkTheme(context)
: Theme.lightTheme(context),
routes: Routes.routes,
onUnknownRoute: Routes.Page404,
);
```
but when I restart the app the locale is set back to English...
is there any way to set the locale permanently?
@harivamshi81189 plz complete example
@harivamshi81189 plz complete example
plz find it above I edited the description of my question
Show debug log
@harivamshi81189
Show debug log
an example that can easily
Please recheck on 2.0.0+3 version
I can reproduce this. Maybe worth mentioning that this is iOS only @Overman775 @aissat ! Here are the logs: (the flutter logs being a print of the locale from a child widget via print(EasyLocalization.of(context).locale);)
These are the logs for the inital load, when everything works as expected:
flutter: de_DE
[log] easy localization: Device locale de_DE
flutter: de_DE
[log] easy localization: Set locale de_DE
flutter: de_DE
flutter: de_DE
flutter: de_DE
[log] easy localization: Device locale de_DE
[log] easy localization: Set locale de_DE
This is how it looks on the reopen:
flutter: en_US
flutter: en_US
flutter: en_US
flutter: de_DE
flutter: en_US
[Crashlytics:Crash] Warning: NSUncaughtExceptionHandler is 'GADRegisterExceptionHandler' in '/Users/moritzmorgenroth/Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../Runner.app/Runner'
[log] easy localization: Device locale de_DE
[log] easy localization: Set locale de_DE
```
Meaning that the local does not get propagated to the child widget, thus probably also not set.
Also notably, the `saveLocale` is set to false in the config:
runApp(EasyLocalization(
supportedLocales: [
const Locale('de', "DE"),
const Locale('en', "US"),
const Locale('es', "ES"),
const Locale('fr', "FR"),
],
fallbackLocale: Locale('de', "DE"),
saveLocale: false,
path: 'assets/localizations',
child: BaseBlocProvider()));
```
From my inspections, this is probably related to the saveLocale functionality, maybe an ios related shared preference thing.
@moritzmorgenroth @harivamshi81189
Try setting up plist.info


@Overman775 the issue is unreleated to the XCode config, I tried all sorts there. But looking at the logs above, you can see that the plugin get the right locale from the native app, but doesn propagate it properly to its child.
@Overman775 @aissat I did further investiagtion, the method findSystemLocale() from intl is returning bad values after the initial startup. I dont think using this method to load the device locale is good practice (See comment above the implementation). Should be woven into the delegate if needed so that context based localization can be used as intended by flutter and overridden if needed. Is the only reason that you are getting the device locale in the tree above the material context to do the preloading?
@harivamshi81189 You can work around the issue by commenting out this line from your MaterialApp:
// locale: EasyLocalization.of(context).locale,
This way the extension will consume the system locale instead of the extension one, meaning that saving the locale in app with the extension will not work, but as you probably also want system level, it works!
@harivamshi81189 You can work around the issue by commenting out this line from your
MaterialApp:// locale: EasyLocalization.of(context).locale,This way the extension will consume the system locale instead of the extension one, meaning that saving the locale in app with the extension will not work, but as you probably also want system level, it works!
@moritzmorgenroth it's working , nice tip
@aissat are you open to contributions? I could make a PR tomorrow putting my thoughts on a solution into code.
@moritzmorgenroth please check my fork, develop branch. I am preparing a new PR today
@Overman775 cool, how long does it usual take for the review? I have some suggestions for some architectural changes that will also solve your latest issue tickets like the black screen, I believe there are some problems with the FutureBuilder as well as your listener etc. Should be quickly resolved though. Ill base my PR onto yours tomorrow then.
@moritzmorgenroth usually quickly. Your cooperation will greatly help the project 馃憤
I fixed black screen bug
Widget build(BuildContext context) {
return Container(
color: widget.preloaderColor,
child: FutureBuilder<List>(
@moritzmorgenroth @Overman775 nice
@Overman775 cool, how long does it usual take for the review? I have some suggestions for some architectural changes that will also solve your latest issue tickets like the black screen, I believe there are some problems with the FutureBuilder as well as your listener etc. Should be quickly resolved though. Ill base my PR onto yours tomorrow then.
agreed about this point
Nice, thanks guys. Looking forward!
@moritzmorgenroth usually quickly. Your cooperation will greatly help the project
I fixed black screen bug
Widget build(BuildContext context) { return Container( color: widget.preloaderColor, child: FutureBuilder<List>(@Overman775 @moritzmorgenroth
About this, I'm working to use this Page to handling errors of this PKG like when failed assets loader like this
About this, I'm working to use this Page to handling errors of this PKG like when failed assets loader like this
Looking god!
I already put a dummy widget in there, but your widget is much better))
@aissat @moritzmorgenroth pr done #99
All of a sudden it started working now. Thank you for your support.
Most helpful comment
@aissat @moritzmorgenroth pr done #99