pub struct Theme {
pub key: Option<KeyRef>,
pub data: Rc<ThemeData>,
pub child: WidgetRef,
}Expand description
Applies a theme to descendant widgets.
A theme describes the colors and typographic choices of an application.
Learn more about Theme on the Flutter YouTube channel.
Descendant widgets obtain the current theme’s ThemeData object using
Theme::of. When a widget uses Theme::of, it is automatically rebuilt if
the theme later changes, so that the changes can be applied.
The Theme widget implies an IconTheme widget, set to the value of the
ThemeData::icon_theme of the data for the Theme.
To interact seamlessly with descendant Cupertino widgets, the Theme widget
provides a CupertinoTheme for its descendants with a CupertinoThemeData inherited
from the nearest ancestor CupertinoTheme or if none exists, derived from the
Material data for the Theme. The values in the Material derived
CupertinoThemeData are overridable through ThemeData::cupertino_override_theme.
The values from an inherited CupertinoThemeData can be overridden by wrapping the
desired subtree with a CupertinoTheme.
See also:
ThemeData, which describes the actual configuration of a theme.AnimatedTheme, which animates theThemeDatawhen it changes rather than changing the theme all at once.MaterialApp, which includes anAnimatedThemewidget configured via theMaterialApp.themeargument.
Fields§
§key: Option<KeyRef>§data: Rc<ThemeData>Specifies the color and typography values for descendant widgets.
Shared, as Dart shares the one ThemeData object: Theme::of hands out this
value, and ThemeData::localize keys its cache on its identity.
child: WidgetRefThe widget below this widget in the tree.
Implementations§
Source§impl Theme
impl Theme
Sourcepub fn new<K>(
data: impl Into<Rc<ThemeData>>,
child: impl IntoWidget<K>,
) -> Theme
pub fn new<K>( data: impl Into<Rc<ThemeData>>, child: impl IntoWidget<K>, ) -> Theme
Applies the given theme data to child.
Sourcepub fn of(app: &mut App, context: BuildContext) -> Rc<ThemeData>
pub fn of(app: &mut App, context: BuildContext) -> Rc<ThemeData>
The data from the closest Theme instance that encloses the given
context.
If the given context is enclosed in a Localizations widget providing
MaterialLocalizations, the returned data is localized according to the
nearest available MaterialLocalizations.
Defaults to ThemeData::fallback if there is no Theme in the given
build context.
When the Theme is actually created in the same build function
(possibly indirectly, e.g. as part of a MaterialApp), the context
argument to the build function can’t be used to find the Theme (since
it’s “above” the widget being returned). In such cases, a Builder can be used
to provide a new scope with a BuildContext that is “under” the Theme.
See also:
ColorScheme::of, a convenience method that returnsThemeData::color_schemefrom the closestThemeancestor. (equivalent toTheme::of(app, context).color_scheme).TextTheme::of, a convenience method that returnsThemeData::text_themefrom the closestThemeancestor. (equivalent toTheme::of(app, context).text_theme).IconTheme::of, that returnsThemeData::icon_themefrom the closestThemeorIconThemeData::fallbackif there is noIconThemeancestor.
Sourcepub fn brightness_of(app: &mut App, context: BuildContext) -> Brightness
pub fn brightness_of(app: &mut App, context: BuildContext) -> Brightness
Retrieves the Brightness to use for descendant Material widgets, based
on the value of ThemeData::brightness in the given context.
If no InheritedTheme can be found in the given context, or its brightness
is null, it will fall back to MediaQueryData.platform_brightness.
See also:
maybe_brightness_of, which returns null if no validInheritedThemeorMediaQueryexists.ThemeData::brightness, the property that takes precedence overMediaQueryData.platform_brightnessfor descendant Material widgets.
Sourcepub fn maybe_brightness_of(
app: &mut App,
context: BuildContext,
) -> Option<Brightness>
pub fn maybe_brightness_of( app: &mut App, context: BuildContext, ) -> Option<Brightness>
Retrieves the Brightness to use for descendant Material widgets, based
on the value of ThemeData::brightness in the given context.
If no InheritedTheme or MediaQuery can be found in the given context, it will
return null.
See also:
ThemeData::brightness, the property that takes precedence overMediaQueryData.platform_brightnessfor descendant Material widgets.brightness_of, which return a default value if no validInheritedThemeorMediaQueryexists, instead of returning null.
Trait Implementations§
Source§impl StatelessWidget for Theme
impl StatelessWidget for Theme
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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
this is PreferredSizeWidget: a widget that implements PreferredSizeWidget
answers with itself, which is what a parent asking an erased child for its preferred
size reads.Auto Trait Implementations§
impl !RefUnwindSafe for Theme
impl !Send for Theme
impl !Sync for Theme
impl !UnwindSafe for Theme
impl Forget for Theme
impl Freeze for Theme
impl Move for Theme
impl Unpin for Theme
impl UnsafeUnpin for Themewhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<ThemeData> is !null: UnsafeUnpin,
PhantomData<RcInner<ThemeData>>: 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.