localizationsDelegates property
The delegates for this app's Localizations widget.
The delegates collectively define all of the localized resources for this application's Localizations widget.
Delegates that produce WidgetsLocalizations and MaterialLocalizations
are included automatically. Apps can provide their own versions of these
localizations by creating implementations of
LocalizationsDelegate
For example: to add support to MaterialLocalizations for a
locale it doesn't already support, say const Locale('foo', 'BR')
,
one could just extend DefaultMaterialLocalizations:
class FooLocalizations extends DefaultMaterialLocalizations {
FooLocalizations(Locale locale) : super(locale);
@override
String get okButtonLabel {
if (locale == const Locale('foo', 'BR'))
return 'foo';
return super.okButtonLabel;
}
}
A FooLocalizationsDelegate
is essentially just a method that constructs
a FooLocalizations
object. We return a SynchronousFuture here because
no asynchronous work takes place upon "loading" the localizations object.
class FooLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
const FooLocalizationsDelegate();
@override
Future<FooLocalizations> load(Locale locale) {
return new SynchronousFuture(new FooLocalizations(locale));
}
@override
bool shouldReload(FooLocalizationsDelegate old) => false;
}
Constructing a MaterialApp with a FooLocalizationsDelegate
overrides
the automatically included delegate for MaterialLocalizations because
only the first delegate of each LocalizationsDelegate.type is used and
the automatically included delegates are added to the end of the app's
localizationsDelegates list.
new MaterialApp(
localizationsDelegates: [
const FooLocalizationsDelegate(),
],
// ...
)
Implementation
final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates