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.

This example shows how you can override the default text and icon color (the "foreground color") of a TextButton with a MaterialStateProperty. 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.
To create a local project with this code sample, run:
flutter create --sample=material.MaterialStateProperty.1 mysample

See also:

Implementers

Constructors

MaterialStateProperty()

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 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) 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.