Flutter: setState() or markNeedsBuild() called during build. This widget cannot be marked as needing to build because the framework is already in the process of building widgets
State was changed while Flutter was building widgets, for example calling setState or a notifier from inside build.
setState() or markNeedsBuild() called during buildThis widget cannot be marked as needing to build because the framework is already in the process of building widgetssetState() called during buildnotifyListeners() was called during buildTried to build dirty widget in the wrong build scope Meaning
Calling setState, notifyListeners() or navigation inside build triggers another build mid-build. Move the work to initState, a post-frame callback (WidgetsBinding.instance.addPostFrameCallback), or an event handler. With Provider, defer notifications triggered from build.
Common causes
- setState() or notifyListeners() called in build()
- Navigator.push in build
- Provider notifier updated during a child's build
- Controller listener calling setState while building
- FutureBuilder/StreamBuilder callback that mutates state
⚡ Quick fix
- Move the call to initState or an event handler
- Wrap in
WidgetsBinding.instance.addPostFrameCallback((_) { … }) - Use
Future.microtaskfor provider updates started in build
Detailed fix by platform
Flutter
WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) setState(() => ready = true); });
How to diagnose
- Call — setState/notifyListeners in build?
- Trigger — Navigation/provider?
- Timing — Need post-frame?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Android license status unknown / licenses not accepted flutter doctor: Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses
- Bad state: Stream has already been listened to Dart: Bad state: Stream has already been listened to
- BoxConstraints forces an infinite width Flutter: BoxConstraints forces an infinite width. These invalid constraints were provided to RenderStack's layout() function (TextField in a Row)
Most viewed in Flutter / Dart
- A RenderFlex overflowed Flutter: A RenderFlex overflowed by x pixels on the right/bottom
- Null check operator used on a null value Dart/Flutter: Null check operator used on a null value
- Unsupported class file major version (Gradle / Java) Android Gradle: Execution failed — Unsupported class file major version 65 / Android Gradle plugin requires Java 17 to run
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026