WidgetStateProperty class - widgets library (original) (raw)
Interface for classes that resolve to a value of type T
based on a widget's interactive "state", which is defined as a set of WidgetStates.
Widget state properties represent values that depend on a widget's "state". The state is encoded as a set of WidgetState values, likeWidgetState.focused, WidgetState.hovered, WidgetState.pressed. For example the InkWell.overlayColor defines the color that fills the ink well when it's pressed (the "splash color"), focused, or hovered. The InkWelluses the overlay color's resolve method to compute the color for the ink well's current state.
ButtonStyle, which is used to configure the appearance of buttons like TextButton, ElevatedButton, and OutlinedButton, has many material state properties. The button widgets keep track of their current material state and resolve the button style's material state properties when their value is needed.
This example shows how the default text and icon color (the "foreground color") of a TextButton can be overridden with aWidgetStateProperty. In this example, the button's text color will be colored differently depending on whether the button is pressed, hovered, or focused.
To create a local project with this code sample, run:
flutter create --sample=widgets.WidgetStateProperty.1 mysample
Performance Consideration
In order for constructed WidgetStateProperty objects to be recognized as equivalent, they need to either be const
objects, or have overrides foroperator== and hashCode.
This comes into play when, for instance, two ThemeData objects are being compared for equality.
For a concrete WidgetStateProperty
object that supports stable equality checks, consider using WidgetStateMapper.
See also:
- MaterialStateProperty, the Material specific version of
WidgetStateProperty
. - WidgetStateColor, a Color that implements
WidgetStateProperty
which is used in APIs that need to accept either a Color or aWidgetStateProperty<Color>
. - WidgetStateMouseCursor, a MouseCursor that implements
WidgetStateProperty
which is used in APIs that need to accept either a MouseCursor or a WidgetStateProperty. - WidgetStateOutlinedBorder, an OutlinedBorder that implements
WidgetStateProperty
which is used in APIs that need to accept either an OutlinedBorder or a WidgetStateProperty. - WidgetStateBorderSide, a BorderSide that implements
WidgetStateProperty
which is used in APIs that need to accept either a BorderSide or a WidgetStateProperty. - WidgetStateTextStyle, a TextStyle that implements
WidgetStateProperty
which is used in APIs that need to accept either a TextStyle or a WidgetStateProperty.
Implementers
- MaterialStateOutlineInputBorder
- MaterialStateUnderlineInputBorder
- WidgetStateBorderSide
- WidgetStateColor
- WidgetStateInputBorder
- WidgetStateMapper
- WidgetStateMouseCursor
- WidgetStateOutlinedBorder
- WidgetStatePropertyAll
- WidgetStateTextStyle
Constructors
This abstract constructor allows extending the class.
WidgetStateProperty.fromMap(WidgetStateMap<T> map)
Creates a property that resolves using a WidgetStateMap.
const
factory
Properties
The hash code for this object.
no setterinherited
A representation of the runtime type of the object.
no setterinherited
Methods
noSuchMethod(Invocation invocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve(Set<WidgetState> states)→ T
Returns a value of type T
that depends on states
.
A string representation of this object.
inherited
Operators
operator ==(Object other)→ bool
The equality operator.
inherited
Static Methods
all<T>(T value)→ WidgetStateProperty<T>
Convenience method for creating a WidgetStateProperty that resolves to a single value for all states.
lerp<T>(WidgetStateProperty<T>? a, WidgetStateProperty<T>? b, double t, T? lerpFunction(T?, T?, double))→ WidgetStateProperty<T?>?
Linearly interpolate between two WidgetStatePropertys.
resolveAs<T>(T value, Set<WidgetState> states)→ T
Resolves the value for the given set of states if value
is aWidgetStateProperty, otherwise returns the value itself.
resolveWith<T>(WidgetPropertyResolver<T> callback)→ WidgetStateProperty<T>
Convenience method for creating a WidgetStateProperty from aWidgetPropertyResolver function alone.