Short answer
Move the state change out of build. Show dialogs and navigate from an event handler, such as onPressed, or after the first frame with WidgetsBinding.instance.addPostFrameCallback in initState. If a ChangeNotifier calls notifyListeners during build, trigger that update from initState or an event instead.
Why the state change is rejected, and the fix
01
setState is called inside build
“The build method in your Flutter code isn't a good place to call setState, either directly or indirectly.” Flutter, Common Flutter errors
build can run many times a second, for example during an animation. Changing state there asks Flutter to rebuild while it is already building. Calculate values in build without saving them, or change state in an event handler or lifecycle method.
02
A dialog or navigation is triggered from build
“The build method isn't the right place to call showDialog because build can be called by the framework for every frame, for example, during an animation.” Flutter, Common Flutter errors
showDialog, Navigator.push and snackbars change the widget tree, so calling them from build hits the same error even without a visible setState. Trigger them from the button that opens the screen, or after the first frame.
// in a StatefulWidget's State @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { if (!mounted) return; showDialog<void>( context: context, builder: (_) => const AlertDialog(title: Text('Welcome')), ); }); }03
Open the dialog as a route instead
“One way to avoid this error is to use the Navigator API to trigger the dialog as a route.” Flutter, Common Flutter errors
When a screen should open with a dialog on top, push both from the button that opens it: first the screen, then the dialog as its own route. Flutter’s docs show this pattern with Navigator and PageRouteBuilder.
04
A ChangeNotifier notifies during build
With Provider and a ChangeNotifier, the same error appears when build calls a method that changes the model and calls notifyListeners, such as starting a data load. Start the load in initState (after the first frame if it notifies right away) or in the model itself, and only read state in build.
Checked against the vendor’s docs on : Flutter docs: Common Flutter errors (setState called during build).
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Flutter “A RenderFlex overflowed” · Flutter “RenderBox was not laid out” · Flutter MissingPluginException · Flutter requires a newer Kotlin Gradle plugin