WidgetStateProperty<T> class abstract

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, like WidgetState.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 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.

This example shows how the default text and icon color (the "foreground color") of a TextButton can be overridden with a WidgetStateProperty. In this example, the button's text color will be Colors.blue when the button is being pressed, hovered, or focused. Otherwise, the text color will be Colors.red.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.WidgetStateProperty.1 mysample

See also:

Implementers

Constructors

WidgetStateProperty()
This abstract constructor allows extending the class.
WidgetStateProperty.fromMap(WidgetStateMap<T> map)
Creates a property that resolves using a WidgetStateMap.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
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.
toString() String
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 a WidgetStateProperty, otherwise returns the value itself.
resolveWith<T>(WidgetPropertyResolver<T> callback) WidgetStateProperty<T>
Convenience method for creating a WidgetStateProperty from a WidgetPropertyResolver function alone.