KLocalizations class

This is the clase you will use to setup and consume localizations, refer to the README for more detailed info.

Inheritance

Constructors

KLocalizations({required Locale locale, required Locale defaultLocale, required List<Locale> supportedLocales, String localizationsAssetsPath = 'assets/translations', bool throwOnMissingTranslation = false, KLocalizationsLoader? loader})

Properties

defaultLocale Locale
Defines the default locale
final
delegate → dynamic
Returns the delegate for KLocalizations
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
locale Locale
no setter
localizationsAssetsPath String
The location of the translation files, by default 'assets/translations'
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportedLocaleNames → dynamic
Returns the supported locale names
no setter
supportedLocales List<Locale>
List of available locales, can be used by localeResolutionCallback, to determine whether a locale is supported or not
final
textDirection TextDirection
Returns TextDirection for the current locale if specified, otherwise returns TextDirection.ltr
no setter
throwOnMissingTranslation bool
Tells KLocalizations whether to throw an exception if a translation is missing, false by default.
final

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. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
getLocaleByCountryCode(String? countryCode, {Locale orElse()?}) Locale
Searches for a given countryCode in the list of supportedLocales, if there is a match the Locale is returned. Oherwise orElse is called if provided. If orElse is not provided, default value will be the first supported locale.
getLocaleByLanguageCode(String? languageCode, {Locale orElse()?}) Locale
Searches for a given languageCode in the list of supportedLocales, if there is a match the Locale is returned. Oherwise orElse is called if provided. If orElse is not provided, default value will be the first supported locale.
load() Future<bool>
Loads translations for current locale
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
setLocale(Locale locale, {bool silent = false}) → void
Set the locale, and notify listeners if silent is false
toString() String
A string representation of this object.
inherited
translate(String key, {Map<String, dynamic>? params}) String
Main method, given a key and a set of params, return the translated for the current _locale

Operators

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

Static Methods

asChangeNotifier({required List<Locale> supportedLocales, required Locale locale, required Locale defaultLocale, String? localizationsAssetsPath, Widget? child, KLocalizationsLoader? loader}) → ChangeNotifierProvider<KLocalizations>
Creates KLocalizations wrapped in a ChangeNotifierProvider After we can get access to KLocalizations by calling KLocalizations.of(context)
of(BuildContext context, {bool listen = true}) KLocalizations?
Obtains the nearest KLocalizations up its widget tree and returns its value.