aissat / easy_localization

Easy and Fast internationalizing your Flutter Apps
https://pub.dev/packages/easy_localization
MIT License
881 stars 312 forks source link

resetLocal crashes if deviceLocale not in supportedLocales #670

Closed bbsmartc closed 2 months ago

bbsmartc commented 2 months ago

resetLocale() crashes if deviceLocale not in supportedLocales, the deviceLocal is not checked before setLocale. currently, i use the following code out of the library

                if (context.supportedLocales.contains(context.deviceLocale)) {
                  context.resetLocale();
                } else {
                  context.setLocale(context.fallbackLocale!);
                }

it might be better to check that in the function resetLocale()

bbsmartc commented 2 months ago

locale.supports() is defined in LocaleExtension on Locale in EasyLocalizationController, it's better to use supportedLocales.any((locale) =>locale.supports(deviceLocale)) instead of supportedLocales.contains(deviceLocale). Because supportedLocales is not saved to local variable in EasyLocalizationController, i did not make a pull request to avoid disrupting the code. it's better to always use selectLocaleFrom(supportedLocale, inputLocale, fallbackLocale) to ensure a fallback, in resetLocale() in EasyLocalizationController, instead of directly assigning the deviceLocale to _local

bbsmartc commented 2 months ago

i will make a pull request