Flutter: Application's locale is not supported by all of its localization delegates

纵然是瞬间 提交于 2019-12-12 15:58:14

问题


Hello I am trying add BottomNavigationBar in flutter app but when i run project error occures :

A MaterialLocalizations delegate that supports the ka_GE locale was not found

This is my app delegates:

  supportedLocales: [
    const Locale('en', 'US'),
    const Locale('ka', 'GE'),
    const Locale('ru', 'RU'),
  ],
  localizationsDelegates: [
    const InfosLocalizationsDelegate(),
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate
  ],
  locale: Locale('ka')

This is Custom LocalizationsDelegate:

class CLocalizationsDelegate
    extends LocalizationsDelegate<CLocalizations> {
  const CLocalizationsDelegate();

  @override
  bool isSupported(Locale locale) =>
      ['en', 'ka', 'ru'].contains(locale.languageCode);

  @override
  Future<CLocalizations> load(Locale locale) async {
    CLocalizations localizations = new CLocalizations(locale);
    await localizations.load();
    print("Load ${locale.languageCode}");
    return localizations;
  }

  @override
  bool shouldReload(CLocalizationsDelegate old) => false;
}

Yeah I know that the problem is 'ka' because MaterialLocalizations doesn't not supports it but I have to solve that problem, so guys can you help me out?


回答1:


You can implement your custom MaterialLocalizations delegate

class MaterialLocalizationKaDelegate extends LocalizationsDelegate<MaterialLocalizations> {
  @override
  bool isSupported(Locale locale) {
    return locale.countryCode == "GE" && locale.languageCode == "ka";
  }

  @override
  Future<MaterialLocalizations> load(Locale locale) async {
    return MaterialLocalizationKa();
  }

  @override
  bool shouldReload(Foo old) {
    return false;
  }
}

class MaterialLocalizationKa extends MaterialLocalizations {
  // TODO: implement KA localization yourself
}


来源:https://stackoverflow.com/questions/53177878/flutter-applications-locale-is-not-supported-by-all-of-its-localization-delega

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!