I18n class

Wrap your widget tree with the I18n widget. This will translate your strings to the current system locale:

import 'package:i18n_extension/i18n_widget.dart';

@override
Widget build(BuildContext context) {
  return I18n(
      child: Scaffold( ... )
  );
}

You can override it with any locale, like this:

return I18n(
    initialLocale: Locale("pt", "BR"),
    child: Scaffold( ... )
Inheritance

Constructors

I18n({Key key, String id, @required Widget child, Locale initialLocale})

Properties

child Widget
final
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
initialLocale Locale
final
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
createState() → _I18nState
Creates the mutable state for this widget at a given location in the tree. [...]
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.info}) String
Returns a string representation of this object.
inherited
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited

Static Properties

forcedLocale Locale
read-only
language String
The language of the current locale, as a lowercase string. For example: "en" or "pt".
read-only
locale Locale
Returns the forced-locale, if it is not null. Otherwise, returns the system-locale.
read-only
localeStr String
The locale, as a lowercase string. For example: "en_us" or "pt_br".
read-only
observeLocale ↔ void Function({Locale newLocale, Locale oldLocale})
This global callback is called whenever the locale changes. Notes: • To obtain the language, you can do: String language = I18n.getLanguage(newLocale); • To obtain the normalized locale as a string, you can do: String localeStr = I18n.trim(newLocale);
read / write
systemLocale Locale
read-only

Static Methods

define(Locale locale) → dynamic
This should be used useful for tests ONLY. To change the locale in the real app, use: I18n.of(context).locale = Locale("en", "US");
forceRebuild(String id) → void
If you have multiple I18n widgets you can call this method to force specific I18n widgets to rebuild. First, give it an id (and not a key), for example: I18n(id:"myWidget", child: ...). [...]
getLanguageFromLocale(Locale locale) String
Return the lowercase language-code of the given locale. Or null if the locale is null.
normalizeLocale(Locale locale) String
Return the string representation of the locale, normalized (trims spaces and underscore).
of(BuildContext context) → _I18nState
Getter: print(I18n.of(context).locale); [...]