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 StringThe Fix
final Map<String, dynamic> json = {'name': null};
final String name = json['name'] ?? 'Unknown';Step-by-Step Fix
- 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
Find the cause
Check JSON parsing, API responses, or map lookups where values might be null but the receiving variable is non-nullable.
- 3
Apply the fix
Use nullable types (String?), provide default values with ??, or validate data before assignment.
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