pub struct Localizations { /* private fields */ }Expand description
Defines the Locale for its child and the localized resources that the
child depends on.
§Defining localized resources
This class is effectively an InheritedWidget. If it’s rebuilt with
a new locale or a different list of delegates or any of its
delegates’ LocalizationsDelegate::should_reload methods returns true,
then widgets that have created a dependency on this widget will be
rebuilt after the resources for the new locale have been loaded.
The Localizations widget also instantiates Directionality in order to
support the appropriate Directionality::of for its localized child.
Each LocalizationsDelegate in delegates produces a collection of localized
resources, an object of type T, one of which is retrieved with Localizations::of.
WidgetsApp creates a Localizations widget so most apps will not need to create one.
The widget app’s Localizations delegates can be initialized with
WidgetsApp.localizationsDelegates. The MaterialApp class also provides a
localizationsDelegates parameter that’s just passed along to the WidgetsApp.
§Loading localized resources
Localized resources are loaded by the list of LocalizationsDelegate
delegates. Each delegate is essentially a factory for a collection
of localized resources. There are multiple delegates because there are
multiple sources for localizations within an app.
If Localizations were to be rebuilt with a new locale then
the widget subtree that corresponds to BuildContext context would
be rebuilt after the corresponding resources had been loaded.
§Localizations widgets
The delegates are the primary parameter.
Implementations§
Source§impl Localizations
impl Localizations
Sourcepub fn new(
locale: Locale,
delegates: Vec<LocalizationsDelegateRef>,
) -> Localizations
pub fn new( locale: Locale, delegates: Vec<LocalizationsDelegateRef>, ) -> Localizations
Create a widget from which localizations (like translated strings) can be obtained.
The delegates must include one for WidgetsLocalizations.
Sourcepub fn override(app: &mut App, context: BuildContext) -> LocalizationsOverride
pub fn override(app: &mut App, context: BuildContext) -> LocalizationsOverride
Overrides the inherited Locale or LocalizationsDelegates for child.
This factory constructor is used for the (rare) situation where part of an app
should be localized for a different locale than the one defined for the device,
or if its localizations should come from a different list of
LocalizationsDelegates than the list defined by WidgetsApp.localizationsDelegates.
For example you could specify that my_widget was only to be localized for
the US English locale:
Localizations::r#override(app, context)
.locale(Locale::new("en").country_code("US"))
.child(my_widget)The locale and delegates parameters default to the Localizations::locale_of
and Localizations delegates values from the enclosing Localizations widget.
The given delegates are consulted before the inherited ones.
Sourcepub fn key(self, key: KeyRef) -> Localizations
pub fn key(self, key: KeyRef) -> Localizations
Dart Localizations(key:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> Localizations
pub fn child<K>(self, child: impl IntoWidget<K>) -> Localizations
The widget below this widget in the tree.
Sourcepub fn is_application_level(self, is_application_level: bool) -> Localizations
pub fn is_application_level(self, is_application_level: bool) -> Localizations
Whether this widget is at the application level.
WidgetsApp sets this to true.
Sourcepub fn locale_of(app: &mut App, context: BuildContext) -> Locale
pub fn locale_of(app: &mut App, context: BuildContext) -> Locale
The locale of the Localizations widget for the widget tree that
corresponds to BuildContext context.
If no Localizations widget is in scope then the Localizations::locale_of
method will throw an exception.
Sourcepub fn maybe_locale_of(app: &mut App, context: BuildContext) -> Option<Locale>
pub fn maybe_locale_of(app: &mut App, context: BuildContext) -> Option<Locale>
The locale of the Localizations widget for the widget tree that
corresponds to BuildContext context.
If no Localizations widget is in scope then this function will return
null.
Sourcepub fn of<T: ?Sized + 'static>(
app: &mut App,
context: BuildContext,
) -> Option<Rc<T>>
pub fn of<T: ?Sized + 'static>( app: &mut App, context: BuildContext, ) -> Option<Rc<T>>
Returns the localized resources object of the given type for the widget
tree that corresponds to the given context.
Returns null if no resources object of the given type exists within
the given context.
This method is typically used by a static factory method on the type
class. For example Flutter’s MaterialLocalizations class looks up Material
resources with a method defined like this:
pub fn of(app: &mut App, context: BuildContext) -> Rc<dyn MaterialLocalizations> {
Localizations::of::<dyn MaterialLocalizations>(app, context).expect(..)
}Trait Implementations§
Source§impl Debug for Localizations
impl Debug for Localizations
Source§impl StatefulWidget for Localizations
impl StatefulWidget for Localizations
Source§type State = LocalizationsState
type State = LocalizationsState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn create_state(&self) -> LocalizationsState
fn create_state(&self) -> LocalizationsState
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for Localizations
impl !Send for Localizations
impl !Sync for Localizations
impl !UnwindSafe for Localizations
impl Forget for Localizations
impl Freeze for Localizationswhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<LocalizationsDelegateRef>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for Localizations
impl Unpin for Localizations
impl UnsafeUnpin for Localizationswhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<LocalizationsDelegateRef>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.