easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

Failed assertion: line 213 pos 14: 'parent.supportedLocales.contains(_locale)': is not true.

Open ZeeshanJelani opened this issue 3 years ago • 3 comments

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.

ZeeshanJelani avatar Aug 23 '21 12:08 ZeeshanJelani

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

LabN36 avatar Feb 16 '22 17:02 LabN36

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'));

apieceofcode1801 avatar Apr 01 '22 09:04 apieceofcode1801

@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);
    }

apieceofcode1801 avatar Apr 01 '22 10:04 apieceofcode1801