Skip to main content

Theme

Struct Theme 

Source
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 the ThemeData when it changes rather than changing the theme all at once.
  • MaterialApp, which includes an AnimatedTheme widget configured via the MaterialApp.theme argument.

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: WidgetRef

The widget below this widget in the tree.

Implementations§

Source§

impl Theme

Source

pub fn new<K>( data: impl Into<Rc<ThemeData>>, child: impl IntoWidget<K>, ) -> Theme

Applies the given theme data to child.

Source

pub fn key(self, key: KeyRef) -> Theme

Dart Theme(key:).

Source

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:

Source

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:

Source

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 over MediaQueryData.platform_brightness for descendant Material widgets.
  • brightness_of, which return a default value if no valid InheritedTheme or MediaQuery exists, instead of returning null.

Trait Implementations§

Source§

impl Clone for Theme

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Theme

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatelessWidget for Theme

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Dart’s 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
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<ThemeData> is !null: Freeze, PhantomData<RcInner<ThemeData>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for Theme

§

impl Unpin for Theme
where Rc<dyn Key>: Unpin, Rc<ThemeData>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for Theme
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatelessKind> for W
where W: StatelessWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>