Null check operator used on a null value 🐦 Flutter / Dart

Dart/Flutter: Null check operator used on a null value

The ! operator was applied to a variable that was null at runtime.

Seen on: Flutter

Meaning

x! promises the compiler that x isn’t null; when it is, the app throws. Common with context-dependent lookups (Navigator, Form keys), late-loaded data and Firebase/plugin results.

Common causes

  • Using ! on data not loaded yet
  • GlobalKey.currentState! before the widget is built
  • Map/JSON lookups returning null
  • Plugin APIs returning null on some platforms

⚡ Quick fix

  1. Replace ! with null-aware handling (?., ??, if (x != null))
  2. Initialise data before use, show a loader meanwhile
  3. Check stack trace for the exact ! location

Detailed fix by platform

Dart

  1. dart
    final user = snapshot.data;
    if (user == null) return const CircularProgressIndicator();
    return Text(user.name ?? 'Guest');

How to diagnose

  1. Line — Which ! failed (stack trace)?
  2. Timing — Data loaded yet?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

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