Scaffold.of() called with a context that does not contain a Scaffold Flutter / Dart Origin: On your device Last updated 4 Nov 2026

Flutter: Scaffold.of() called with a context that does not contain a Scaffold

You called Scaffold.of(context) (or ScaffoldMessenger) using the same BuildContext that created the Scaffold, which is above it in the tree.

Exact message you may see Scaffold.of() called with a context that does not contain a ScaffoldScaffold.of() called with a context that does not contain a Scaffold. No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of()ScaffoldMessenger.of() called with a context that does not contain a ScaffoldMessenger
Seen on: Flutter

Meaning

of(context) looks upward from the context. The context of the widget that builds the Scaffold is its parent, so it cannot find it. Use a Builder widget to get a context below the Scaffold, or split the body into its own widget. For snack bars use ScaffoldMessenger.of(context) from a context under MaterialApp.

Common causes

  • of(context) in the same build method that returns the Scaffold
  • Using the State's context from before Scaffold
  • Calling from initState or a static function
  • Context taken from a different route
  • Old Scaffold.of(context).showSnackBar API

⚡ Quick fix

  1. Wrap the call site in Builder(builder: (context) => …)
  2. Extract the body into a separate widget
  3. Use ScaffoldMessenger.of(context).showSnackBar(...)

Detailed fix by platform

Flutter

  1. Scaffold(body: Builder(builder: (ctx) => TextButton(onPressed: () => ScaffoldMessenger.of(ctx).showSnackBar(const SnackBar(content: Text('Hi'))), child: const Text('Show'))))

How to diagnose

  1. Context — Above or below Scaffold?
  2. API — ScaffoldMessenger?
  3. Route — Same route?

🔧 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…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…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…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…MediaQuery.of() called with a context that does not contain a MediaQuery — Flutter: MediaQuery.of() called with a context that does not contain a MediaQuery (Flutter / Dart)MediaQuery.of() calle…Navigator operation requested with a context that does not include a Navigator — Flutter: Navigator operation requested with a context that does not include a Navigator (Flutter / Dart)Navigator operation r…No Material widget found — Flutter: No Material widget found. TextField widgets require a Material widget ancestor (Flutter / Dart)No Material widget fo…Scaffold.…

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.