Open bratan opened 4 years ago
Can you detect the language change in localeResolutionCallback
then rebuild the LocalizationProvider
?
There are some issues preventing this from working currently but yes, I think this will be the way to go.
Thanks for the great package, we may be using it in our app. Is this enhancement still planned?
@bratan Can you elaborate on why the flutter_device_locale
package is needed. The same functionality and the syncing is available in plain Flutter via WidgetsBinding.instance.addObserver(...)
or am I missing something?
@kuhnroyal - Because of some iOS issues where different values for the current/selected locale are returned depending on the environment (debug/release) and device type simulator/real device.
So by using flutter_device_locale the real locale is always used regardless of the environment.
More info: https://github.com/flutter/flutter/issues/14128 https://github.com/bratan/flutter_translate/pull/15
@bratan Thanks, Right I now remember this issue. I though this is solved by adding the correct plist entries tho.
@bratan what about doing this
final currentLocale = WidgetsBinding.instance.window.locale;
final locale = currentLocale != null && currentLocale.countryCode != null
? currentLocale
: Localizations.localeOf(context);
to avoid using flutter_device_locale
, btw any progress on this issue? thanks for this great package!
Hi @bratan is there any update on this issue? Thanks.
Hi, there is no update currently as I`m quite busy these days, probably in the near future.
If anyone wants to implement this themselves, you can use a WidgetsBindingObserver and override didChangeLocales(). Do this with a StatefulWidget below LocalizedApp and above MaterialApp.
When a system locale change is detected, you can do something like this:
Future<void> _didChangeLocales(
BuildContext context,
List<Locale>? locales,
) async {
if (locales != null && locales.isNotEmpty &&
locales.first != LocalizedApp.of(context).delegate.currentLocale) {
if (Platform.isAndroid) {
Restart.restartApp();
}
}
}
In my case, I'm restarting the app natively for Android, due to problems trying to force-rebuild the entire widget tree. I'm using the restart_app plugin to do that.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Add an option to automatically sync the current locale with the system locale.
So when the system locale is changed, the current/app locale will be reloaded as well (if supported).
Reference: https://github.com/bratan/flutter_translate/issues/20