FlutterLocalization class

Coordinates the selected locale and the translations Flutter loads.

This object is a ChangeNotifier. Listen to FlutterLocalization.instance with FlutterLocalization.addListener and FlutterLocalization.removeListener, or with a ListenableBuilder, and pass currentLocale to MaterialApp.locale so package strings and Flutter's own locale stay aligned. Remove a listener when its owner is disposed. The shared instance is not meant to be disposed.

Inheritance

Properties

currentLocale → Locale?
The locale the app should display.
no setter
fontFamily → String?
Provides the font family configured for the current locale.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
localizationsDelegates → Iterable<LocalizationsDelegate>
Apply all the needed delegate and the package delegate for the app. This will use at the MaterialApp.
no setter
onTranslatedLanguage ↔ TranslatorCallback?
Single callback invoked after init or translate changes the locale.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
supportedLanguageCodes → List<String>
Get the list of supported language code provided by the init function
no setter
supportedLocaleIdentifiers → List<String>
Full identifiers for the locales provided by init.
no setter
supportedLocales → Iterable<Locale>
Generate the supported locales for the app. This will use at the MaterialAap
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object.
inherited
ensureInitialized() → Future<void>
Loads the saved locale so currentLocale is available before runApp.
getLanguageName({String? languageCode}) → String
Returns the language's own name for languageCode.
init({required String initLanguageCode, LocalizationSource source = LocalizationSource.map, List<MapLocale>? mapLocales, List<JsonLocale>? jsonLocales}) → void
Initializes supported locales and selects the locale to display.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() → String
A string representation of this object.
inherited
translate(String localeTag, {bool save = true}) → void
Call this function at where you want to translate the app like by pressing the button or any actions. localeTag may be a language code (en) or a full locale tag (en-US or zh-Hant).
translateLocale(Locale locale, {bool save = true}) → void
Changes the app to the supported locale matching locale.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

instance → FlutterLocalization
The instance object of FlutterLocalization class.
final