dart Flutter:应用程序的本地化委托并不支持应用程序的本地化

af7jpaap  于 2023-07-31  发布在  Flutter
关注(0)|答案(2)|浏览(131)

你好,我正在尝试添加BottomNavigationBar在Flutter应用程序,但当我运行项目错误occures:

A MaterialLocalizations delegate that supports the ka_GE locale was not found

字符串
这是我的APP委托:

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


这是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;
}


是的,我知道问题是'ka',因为MaterialLocalizations不支持它,但我必须解决这个问题,所以伙计们,你们能帮我吗?

ldioqlga

ldioqlga1#

添加 * GlobalCupertino Localizations * 到localizationsDelegates也可以解决问题。

return MaterialApp(
  localizationsDelegates: const [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  // ...
);

字符串

2skhul33

2skhul332#

您可以实现自定义MaterialLocalizations委托

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
}

字符串

相关问题