easy_localization
easy_localization copied to clipboard
Failed assertion: line 213 pos 14: 'parent.supportedLocales.contains(_locale)': is not true.
on changing local language EasyLocalization.of(context).setLocale(Locale('nl', 'NL')); when i run this code. i get this error [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 'package:easy_localization/src/easy_localization_app.dart': Failed assertion: line 213 pos 14: 'parent.supportedLocales.contains(_locale)': is not true.
I faced the same error, in my case i provided the wrong locale string hence.
Internally for this error your code breaks at this link
assert(parent.supportedLocales.contains(_locale));
which means your supported locale doesn't have what you provided at setLocale
in my case i was providing Locale('en, 'US')
instead of Locale('en', '')
hope it helps somebody
I faced the same error. I thought it will select the fallback locale in the case your locale is not listed on the supported locales. But it throws the error.
EasyLocalization(
child: App(),
supportedLocales: const [Locale('en', 'US'), Locale('ja', 'JP')],
fallbackLocale: const Locale('en', 'US'),
path: 'assets/translations'));
@ZeeshanJelani You can check if the locale is listed on the supported locales before setting it. For example:
const locale = Locale('nl', 'NL');
if (context.supportedLocales.contains(locale))) {
context.setLocale(locale);
}