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
- Replace ! with null-aware handling (?., ??, if (x != null))
- Initialise data before use, show a loader meanwhile
- Check stack trace for the exact ! location
Detailed fix by platform
Dart
- dart
final user = snapshot.data; if (user == null) return const CircularProgressIndicator(); return Text(user.name ?? 'Guest');
How to diagnose
- Line — Which ! failed (stack trace)?
- 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:
Similar errors
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026