setState() or markNeedsBuild() called during build Flutter / Dart Origin: On your device Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Flutter

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

  1. Move the call to initState or an event handler
  2. Wrap in WidgetsBinding.instance.addPostFrameCallback((_) { … })
  3. Use Future.microtask for provider updates started in build

Detailed fix by platform

Flutter

  1. WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) setState(() => ready = true); });

How to diagnose

  1. Call — setState/notifyListeners in build?
  2. Trigger — Navigation/provider?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Android license status unknown / licenses not accepted — flutter doctor: Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses (Flutter / Dart)Android license statu…Bad state: Stream has already been listened to — Dart: Bad state: Stream has already been listened to (Flutter / Dart)Bad state: Stream has…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) (Flutter / Dart)BoxConstraints forces…Cleartext HTTP traffic not permitted — Flutter (Android): java.io.IOException: Cleartext HTTP traffic to api.example.com not permitted (Flutter / Dart)Cleartext HTTP traffi…Dependency requires compileSdk 34 or later — Android Gradle: Execution failed for task ':app:checkDebugAarMetadata'. Dependency requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs (Flutter / Dart)Dependency requires c…Error: Could not find the correct Provider — Flutter: Error: Could not find the correct Provider<CartModel> above this Consumer<CartModel> Widget (Flutter / Dart)Error: Could not find…Looking up a deactivated widget's ancestor is unsafe — Flutter: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable (Flutter / Dart)Looking up a deactiva…Modifying state during view update — SwiftUI: Modifying state during view update, this will cause undefined behavior (iOS)Modifying state durin…setState(…

Explore the map of this error Full error map →

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