Dart: type 'Null' is not a subtype of type 'String' in type cast
A value that was null at runtime was cast or used as a non-nullable type, most often when parsing JSON.
type 'Null' is not a subtype of type 'String'type 'Null' is not a subtype of type 'int' in type casttype 'Null' is not a subtype of type 'List<dynamic>'type 'Null' is not a subtype of type 'bool'type 'Null' is not a subtype of type Meaning
Dart's sound null safety makes as String fail if the key is missing or null. Make the field nullable (String?), provide a default (json['name'] ?? ''), or validate the payload. The message names the target type; the stack trace points to the line.
Common causes
- JSON key missing or null cast with
as String - fromJson with required non-nullable fields
- API returning null for optional data
- Wrong key name (typo)
- Platform channel returning null
⚡ Quick fix
- Use nullable types or
??defaults - Validate the JSON before casting
- Use code generation (json_serializable) with
@JsonKey(defaultValue: …)
Detailed fix by platform
Dart
name: json['name'] as String? ?? ''
How to diagnose
- Key — Present in the JSON?
- Type — Nullable in model?
- Default — Provided?
🔧 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
- FormatException: Unexpected character Dart: FormatException: Unexpected character (at character 1) <!DOCTYPE html> — jsonDecode of an HTML page
- LateInitializationError: Field has not been initialized Dart: LateInitializationError: Field 'controller' has not been initialized
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