Skip to main content

WidgetStateColor

Struct WidgetStateColor 

Source
pub struct WidgetStateColor { /* private fields */ }
Expand description

Defines a Color that is also a WidgetStateProperty.

This class exists to enable widgets with Color valued properties to also accept WidgetStateProperty<Color> values. A widget state color property represents a color which depends on a widget’s “interactive state”. This state is represented as a set of WidgetStates, like WidgetState::Pressed, WidgetState::Focused and WidgetState::Hovered.

WidgetStateColor should only be used with widgets that document their support, like TimePickerThemeData.dayPeriodColor.

A WidgetStateColor can be created in one of the following ways:

  1. Use WidgetStateColor::resolve_with and pass in a callback that will be used to resolve the color in the given states.
  2. Use WidgetStateColor::from_map to assign a value using a WidgetStateMap.

It is the Color it is in Dart once erased with into_any (or .into()): an AnyColor whose value is the color resolved in the default state (the empty set of states), Dart’s super(defaultValue), and whose extension is this object, recovered with color.extension::<WidgetStateColor>().

Implementations§

Source§

impl WidgetStateColor

Source

pub fn resolve_with( callback: impl Fn(&WidgetStates) -> Color + 'static, ) -> WidgetStateColor

Creates a WidgetStateColor from a WidgetPropertyResolver<Color> callback function.

If used as a regular color, the color resolved in the default state (the empty set of states) will be used.

The given callback parameter must return a non-null color in the default state.

Source

pub fn from_map(map: WidgetStateMap<Color>) -> WidgetStateColor

Creates a WidgetStateColor from a WidgetStateMap<Color>.

This constructor’s resolve method finds the first entry whose key is satisfied by the set of states, and returns its associated value. It should only be used with widgets that document support for WidgetStateColor (panics if used as a normal Color with no key satisfied by the empty set of states).

To prevent a situation where each WidgetStatesConstraint isn’t satisfied by the given set of states, consider adding WidgetState::any as the final WidgetStateMap key.

Source

pub fn transparent() -> WidgetStateColor

A constant whose value is transparent for all states.

Source

pub fn into_any(self) -> AnyColor

The color as the Color it is in Dart: the default-state value, carrying this object as the extension.

Trait Implementations§

Source§

impl ColorExtension for WidgetStateColor

Source§

fn as_any(&self) -> &dyn Any

The extension as Any, for Dart’s is checks (AnyColor::extension).
Source§

fn eq_extension(&self, other: &dyn ColorExtension) -> bool

Dart’s == override on the subclass, called once the values compared equal. other is the same runtime type when it downcasts; any other type is unequal, as Dart’s runtimeType check makes it.
Source§

impl Debug for WidgetStateColor

Source§

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

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

impl From<WidgetStateColor> for AnyColor

Source§

fn from(color: WidgetStateColor) -> AnyColor

Converts to this type from the input type.
Source§

impl WidgetStateProperty<Color> for WidgetStateColor

Source§

fn resolve(&self, states: &WidgetStates) -> Color

Returns a Color that’s to be used when a component is in the specified state.

Source§

fn as_any(&self) -> &dyn Any

Downcast support for Dart’s is checks in ==.
Source§

fn as_mapper(&self) -> Option<&WidgetStateMapper<Color>>

Dart’s other is WidgetStateMapper<T>: the mapper this property is, if it is one, as the private mapper subclasses of WidgetStateColor and the rest are.
Source§

fn eq_property(&self, other: &dyn WidgetStateProperty<Color>) -> bool

Dart’s ==. Identity unless a class overrides it, as WidgetStatePropertyAll and WidgetStateMapper do.
Source§

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

Dart’s WidgetStateProperty.debugFillProperties, from Diagnosticable: a property adds its own fields.

Auto Trait Implementations§

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> 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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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>