MaterialStatesController typedef

  1. @Deprecated('Use WidgetStatesController instead. ' 'Moved to the Widgets layer to make code available outside of Material. ' 'This feature was deprecated after v3.19.0-0.3.pre.')
MaterialStatesController = WidgetStatesController

Manages a set of MaterialStates and notifies listeners of changes.

Used by widgets that expose their internal state for the sake of extensions that add support for additional states. See TextButton for an example.

The controller's value is its current set of states. Listeners are notified whenever the value changes. The value should only be changed with update; it should not be modified directly.

The controller's value represents the set of states that a widget's visual properties, typically MaterialStateProperty values, are resolved against. It is not the intrinsic state of the widget. The widget is responsible for ensuring that the controller's value tracks its intrinsic state. For example one cannot request the keyboard focus for a widget by adding MaterialState.focused to its controller. When the widget gains the or loses the focus it will update its controller's value and notify listeners of the change.

When calling setState in a MaterialStatesController listener, use the SchedulerBinding.addPostFrameCallback to delay the call to setState after the frame has been rendered. It's generally prudent to use the SchedulerBinding.addPostFrameCallback because some of the widgets that depend on MaterialStatesController may call update in their build method. In such cases, listener's that call setState - during the build phase - will cause an error.

See also:

  • WidgetStatesController, the non-Material version that can be used interchangeably with MaterialStatesController.

Implementation

@Deprecated(
  'Use WidgetStatesController instead. '
  'Moved to the Widgets layer to make code available outside of Material. '
  'This feature was deprecated after v3.19.0-0.3.pre.'
)
typedef MaterialStatesController = WidgetStatesController;