Dart: The property 'length' can't be unconditionally accessed because the receiver can be 'null'
With null safety you used . on a nullable value; Dart requires a null check first.
The property can't be unconditionally accessed because the receiver can be 'null'The method can't be unconditionally invoked because the receiver can be 'null'The operator '[]' can't be unconditionally invoked because the receiver can be 'null'Try making the call conditional (using '?.') or adding a null check (as '!') Meaning
Use ?. (safe access), ! (only if you are certain), a null check if (x != null), or ?? for a default. Prefer making the data non-nullable at the source. The analyzer message names the property and the nullable expression.
Common causes
- Accessing members of a
T?value - Nullable API return (Map lookup, Future results)
- Optional widget parameters used directly
- JSON fields typed nullable
- Migrated code
⚡ Quick fix
- Use
x?.length ?? 0 - Add
if (x == null) return;before use - Change the model to non-nullable where data is guaranteed
Detailed fix by platform
Dart
final len = list?.length ?? 0;
How to diagnose
- Value — Truly nullable?
- Fallback — Default OK?
- Source — Make non-null?
🔧 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
- Bad state: No element Dart: Bad state: No element — .first, .last or .single on an empty list
- LateInitializationError: Field has not been initialized Dart: LateInitializationError: Field 'controller' has not been initialized
- Non-nullable instance field must be initialized Dart: Non-nullable instance field 'name' must be initialized. Try adding an initializer expression, or a generative constructor that initializes it, or mark it 'late'
Most viewed in Flutter / Dart
- setState() called after dispose() Flutter: setState() called after dispose(): _MyState#1a2b3 (lifecycle state: defunct, not mounted)
- A RenderFlex overflowed Flutter: A RenderFlex overflowed by x pixels on the right/bottom
- SocketException: Failed host lookup Flutter: Unhandled Exception: SocketException: Failed host lookup: 'api.example.com' (OS Error: No address associated with hostname, errno = 7)
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