diff --git a/packages/flutter/lib/src/material/material_state.dart b/packages/flutter/lib/src/material/material_state.dart index c1d23d622c..78f7ba3bff 100644 --- a/packages/flutter/lib/src/material/material_state.dart +++ b/packages/flutter/lib/src/material/material_state.dart @@ -760,6 +760,14 @@ class MaterialStatePropertyAll implements MaterialStateProperty { /// [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. class MaterialStatesController extends ValueNotifier> { /// Creates a MaterialStatesController. MaterialStatesController([Set? value]) : super({...?value});