type 'Null' is not a subtype of type 'String'

type 'Null' is not a subtype of type 'String'

Quick Answer

A null value was assigned or passed where a non-nullable String was expected.

Why This Happens

In Dart with null safety, non-nullable types cannot hold null. This error occurs when a null value flows into a non-nullable String parameter, often from JSON parsing or API responses. You should declare the type as nullable (String?) or provide a default value.

The Problem

final Map<String, dynamic> json = {'name': null};
final String name = json['name']; // null assigned to String

The Fix

final Map<String, dynamic> json = {'name': null};
final String name = json['name'] ?? 'Unknown';

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: type 'Null' is not a subtype of type 'String'. This indicates a null value where a non-nullable type was expected.

  2. 2

    Find the cause

    Check JSON parsing, API responses, or map lookups where values might be null but the receiving variable is non-nullable.

  3. 3

    Apply the fix

    Use nullable types (String?), provide default values with ??, or validate data before assignment.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free