type 'Null' is not a subtype of type 'String' Flutter / Dart Origin: On your device OSI layer 7 · Application Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Flutter

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

  1. Use nullable types or ?? defaults
  2. Validate the JSON before casting
  3. Use code generation (json_serializable) with @JsonKey(defaultValue: …)

Detailed fix by platform

Dart

  1. name: json['name'] as String? ?? ''

How to diagnose

  1. Key — Present in the JSON?
  2. Type — Nullable in model?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Bad state: No element — Dart: Bad state: No element — .first, .last or .single on an empty list (Flutter / Dart)Bad state: No elementFormatException: Unexpected character — Dart: FormatException: Unexpected character (at character 1) <!DOCTYPE html> — jsonDecode of an HTML page (Flutter / Dart)FormatException: Unex…LateInitializationError: Field has not been initialized — Dart: LateInitializationError: Field 'controller' has not been initialized (Flutter / Dart)LateInitializationErr…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' (Flutter / Dart)Non-nullable instance…Null check operator used on a null value — Dart/Flutter: Null check operator used on a null value (Flutter / Dart)Null check operator u…RangeError (index): Invalid value — Dart: RangeError (index): Invalid value: Valid value range is empty: 0 (Flutter / Dart)RangeError (index): I…The named parameter is required, but there's no corresponding argument — Dart: The named parameter 'key' is required, but there's no corresponding argument (Flutter / Dart)The named parameter i…The property/method can't be unconditionally accessed because the receiver can be null — Dart: The property 'length' can't be unconditionally accessed because the receiver can be 'null' (Flutter / Dart)The property/method c…type 'Nul…

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.