Reputation: 455
The latest version of easy_localization package is very different than any tutorial or article online.
I struggled a bit with the new version but i got stuck when i tried to create a button to change language dynamically. The old way was data = EasyLocalizationProvider.of(context).data, and i insert data.changeLocale(Locale(ar-SA)); inside onPressed function, that's it. But i can't find the changeLocale function, nor the EasyLocalizationProvider class.
How can i implement this using the latest version?
Thanks in advance...
Upvotes: 0
Views: 6865
Reputation: 301
in my case i used:
context.setLocale(const Locale('uk'));
and got an error: "parent.supportedLocales.contains(locale)': is not true." so i used this:
context.setLocale(const Locale('uk', ''));
Upvotes: 0
Reputation: 13803
in my case, I made silly mistake
I assign
final locale = Locale("en-US");
context.setLocale(locale);
instead of
final locale = Locale("en", "US");
context.setLocale(locale);
Upvotes: 0
Reputation: 1
Ensure to add language to supportedLocales as done in main supportedLocales:
[Locale('en', 'US'), Locale('tr', 'TR'), Locale("ar")],
Upvotes: 0
Reputation: 685
Use this code:
context.locale = Locale('ar', 'SA');
or:
EasyLocalization.of(context).locale = Locale('ar', 'SA');
Upvotes: 3
Reputation: 455
i found the answer... i inserted this inside the onPressed of the button "context.locale = Locale('ar', 'SA');" and it changed the language of the app...
Upvotes: 3