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';

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( ... )


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


child Widget
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
initialLocale Locale
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


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
createState() → _I18nState
Creates the mutable state for this widget at a given location in the tree. [...]
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. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String name, DiagnosticsTreeStyle style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel: DiagnosticLevel.info}) String
Returns a string representation of this object.
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


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

Static Properties

forcedLocale Locale
language String
The language of the current locale, as a lowercase string. For example: "en" or "pt".
locale Locale
Returns the forced-locale, if it is not null. Otherwise, returns the system-locale.
localeStr String
The locale, as a lowercase string. For example: "en_us" or "pt_br".
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

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); [...]