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

2

32

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?

Kitchenmaid answered 6/11, 2018 at 18:29 Comment(1)
You have to make your own MaterializationLocalizations for kaBibbie
A
23

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
}
Americano answered 6/11, 2018 at 19:9 Comment(3)
Kindly guide how to make use of this codePostulant
#57902861Postulant
Can I just ignore this error in case my app has not been internationalized yet?Penland
S
57

Adding GlobalCupertinoLocalizations (from flutter_localizations) to the localizationsDelegates also solves the problem.

return MaterialApp(
  localizationsDelegates: const [
    GlobalMaterialLocalizations.delegate,
    GlobalWidgetsLocalizations.delegate,
    GlobalCupertinoLocalizations.delegate,
  ],
  // ...
);
Smallish answered 14/4, 2022 at 17:58 Comment(4)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Destroyer
This was the perfect answer. GlobalCupertinoLocalizations.delegate, was missing in my code.Randy
This is should be the correct answer. +1 vote. Thank you so much.Overreact
Right, GlobalCupertinoLocalizations.delegate, was missing in my code too. Great answer.Her
A
23

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
}
Americano answered 6/11, 2018 at 19:9 Comment(3)
Kindly guide how to make use of this codePostulant
#57902861Postulant
Can I just ignore this error in case my app has not been internationalized yet?Penland

© 2022 - 2024 — McMap. All rights reserved.