AppLocale class

The fruit of labour that LocaleDelegate produces.

Get the current instance inside any widget (except the main one) through LocaleDelegate.of(context) & use localValue to get the localized value

  @override
  Widget build(BuildContext context) {
    var appLocale = LocaleDelegate.of(context);
    var someText = appLocale.localValue('title');
    // text with placeholder parameter can be replaced
    // e.g.: 'message': 'To {to}, This is a sample Message, from {from}'
    var someTextWithParameter = appLocale.localValue('message', {'to': 'World', 'from': 'Happy'});
  }

Constructors

AppLocale.new(Locale locale)
Default constructor
factory

Properties

currentLocale String
locale in unicode string format
no setter
hashCode int
The hash code for this object.
no setterinherited
locale Locale
The application locale loaded (or to be loaded).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

load(String defaultContainerDirectory, [Locale? defaultLocale]) Future<bool>
Load the appropriate json file from asset & parse it.
localValue(String key, [Map<String, dynamic>? values]) String
Get the value of the key from the provide language json file. Additional values can be provided to substitute {placeholders}.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
updateValue(Map<String, dynamic> newValues) bool
Set additional (or Update existing) runtime values. Some values are not determined until the application starts (i.e. set during runtime).

Operators

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

Static Methods

of(BuildContext context) AppLocale
Get the current AppLocale instance for the context
setInterpolationOptions(InterpolationOption interpolationOption) → void