MaterialStateProperty<T> class
Null safety
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 MaterialStates.
Material state properties represent values that depend on a widget's material "state". The state is encoded as a set of MaterialState values, like MaterialState.focused, MaterialState.hovered, MaterialState.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 InkWell uses 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.
Colors.blue
when the button is being pressed, hovered,
or focused. Otherwise, the text color will be Colors.red
.
flutter create --sample=material.MaterialStateProperty.1 mysample
See also:
- MaterialStateColor, a Color that implements
MaterialStateProperty
which is used in APIs that need to accept either a Color or aMaterialStateProperty<Color>
. - MaterialStateMouseCursor, a MouseCursor that implements
MaterialStateProperty
which is used in APIs that need to accept either a MouseCursor or a MaterialStateProperty<MouseCursor>. - MaterialStateOutlinedBorder, an OutlinedBorder that implements
MaterialStateProperty
which is used in APIs that need to accept either an OutlinedBorder or a MaterialStateProperty<OutlinedBorder>. - MaterialStateOutlineInputBorder, an OutlineInputBorder that implements
MaterialStateProperty
which is used in APIs that need to accept either an OutlineInputBorder or a MaterialStateProperty<OutlineInputBorder>. - MaterialStateUnderlineInputBorder, an UnderlineInputBorder that implements
MaterialStateProperty
which is used in APIs that need to accept either an UnderlineInputBorder or a MaterialStateProperty<UnderlineInputBorder>. - MaterialStateBorderSide, a BorderSide that implements
MaterialStateProperty
which is used in APIs that need to accept either a BorderSide or a MaterialStateProperty<BorderSide>. - MaterialStateTextStyle, a TextStyle that implements
MaterialStateProperty
which is used in APIs that need to accept either a TextStyle or a MaterialStateProperty<TextStyle>.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited
-
resolve(
Set< MaterialState> states) → T -
Returns a value of type
T
that depends onstates
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
all<
T> (T value) → MaterialStateProperty< T> - Convenience method for creating a MaterialStateProperty that resolves to a single value for all states.
-
lerp<
T> (MaterialStateProperty< T> ? a, MaterialStateProperty<T> ? b, double t, T? lerpFunction(T?, T?, double)) → MaterialStateProperty<T?> ? - Linearly interpolate between two MaterialStatePropertys.
-
resolveAs<
T> (T value, Set< MaterialState> states) → T -
Resolves the value for the given set of states if
value
is a MaterialStateProperty, otherwise returns the value itself. -
resolveWith<
T> (MaterialPropertyResolver< T> callback) → MaterialStateProperty<T> - Convenience method for creating a MaterialStateProperty from a MaterialPropertyResolver function alone.