Skip to content

Instantly share code, notes, and snippets.

@bartekpacia
Created October 2, 2022 21:31
Show Gist options
  • Save bartekpacia/a0bd6cfee4271f501b2f36a41ff2ac79 to your computer and use it in GitHub Desktop.
Save bartekpacia/a0bd6cfee4271f501b2f36a41ff2ac79 to your computer and use it in GitHub Desktop.
Useful localization-related extensions in Flutter.
extension BuildContextLocalizations on BuildContext {
Locale get locale => Localizations.localeOf(this);
String get languageCode => locale.toLanguageTag();
AppLocalizations get l10n => AppLocalizations.of(this)!;
List<Locale> get supportedLocales => AppLocalizations.supportedLocales;
List<Locale> get realSupportedLocales => AppLocalizationsX.supportedLocales;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment