Skip to main content

LocalizationsDelegate

Trait LocalizationsDelegate 

Source
pub trait LocalizationsDelegate<T: ?Sized + 'static>: Debug + 'static {
    // Required methods
    fn is_supported(&self, locale: &Locale) -> bool;
    fn load(&self, app: &mut App, locale: &Locale) -> CompleterFuture<Rc<T>> ⓘ;
    fn should_reload(&self, old: &Self) -> bool;
}
Expand description

A factory for a set of localized resources of type T, to be loaded by a Localizations widget.

Typical applications have one Localizations widget which is created by the WidgetsApp and configured with the app’s localizationsDelegates parameter (a list of delegates). The delegate’s type is used to identify the object created by an individual delegate’s load method.

An example of a class used as the value of T here would be MaterialLocalizations.

Required Methods§

Source

fn is_supported(&self, locale: &Locale) -> bool

Whether resources for the given locale can be loaded by this delegate.

Return true if the instance of T loaded by this delegate’s load method supports the given locale’s language.

Source

fn load(&self, app: &mut App, locale: &Locale) -> CompleterFuture<Rc<T>> ⓘ

Start loading the resources for locale. The returned future completes when the resources have finished loading.

It’s assumed that this method will return an object that contains a collection of related resources (typically defined with one method per resource). The object will be retrieved with Localizations::of.

A delegate whose resources are at hand returns CompleterFuture::ready, Dart’s SynchronousFuture: the Localizations widget then builds at once instead of deferring the first frame until the future completes.

Source

fn should_reload(&self, old: &Self) -> bool

Returns true if the resources for this delegate should be loaded again by calling the load method.

This method is called whenever its Localizations widget is rebuilt. If it returns true then dependent widgets will be rebuilt after load has completed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§