didChangeLocales method
Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.
This method exposes notifications from dart:ui.PlatformDispatcher.onLocaleChanged.
Implementation
@override
void didChangeLocales(List<Locale>? locales) {
Get.asap(() {
final deviceLocale = Get.deviceLocale;
if (deviceLocale == null) {
return;
}
final appLocale = Get.locale;
final followsDeviceLocale =
!localeSetExplicitly &&
config.locale == null &&
(appLocale == null || appLocale == _appliedDeviceLocale);
if (followsDeviceLocale) {
_appliedDeviceLocale = deviceLocale;
// Apply the device locale without going through Get.updateLocale,
// so automatic adoption is never recorded as an explicit choice.
Get.locale = deviceLocale;
Get.forceAppUpdate();
}
});
}