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:
- Use
WidgetStateColor::resolve_withand pass in a callback that will be used to resolve the color in the given states. - Use
WidgetStateColor::from_mapto assign a value using aWidgetStateMap.
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
impl WidgetStateColor
Sourcepub fn resolve_with(
callback: impl Fn(&WidgetStates) -> Color + 'static,
) -> WidgetStateColor
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.
Sourcepub fn from_map(map: WidgetStateMap<Color>) -> WidgetStateColor
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.
Sourcepub fn transparent() -> WidgetStateColor
pub fn transparent() -> WidgetStateColor
A constant whose value is transparent for all states.
Trait Implementations§
Source§impl ColorExtension for WidgetStateColor
impl ColorExtension for WidgetStateColor
Source§fn eq_extension(&self, other: &dyn ColorExtension) -> bool
fn eq_extension(&self, other: &dyn ColorExtension) -> bool
== 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
impl Debug for WidgetStateColor
Source§impl From<WidgetStateColor> for AnyColor
impl From<WidgetStateColor> for AnyColor
Source§fn from(color: WidgetStateColor) -> AnyColor
fn from(color: WidgetStateColor) -> AnyColor
Source§impl WidgetStateProperty<Color> for WidgetStateColor
impl WidgetStateProperty<Color> for WidgetStateColor
Source§fn resolve(&self, states: &WidgetStates) -> Color
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_mapper(&self) -> Option<&WidgetStateMapper<Color>>
fn as_mapper(&self) -> Option<&WidgetStateMapper<Color>>
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
fn eq_property(&self, other: &dyn WidgetStateProperty<Color>) -> bool
==. Identity unless a class overrides it, as WidgetStatePropertyAll and
WidgetStateMapper do.Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
WidgetStateProperty.debugFillProperties, from Diagnosticable: a property
adds its own fields.