type 'List<dynamic>' is not a subtype of type 'List<String>'

type 'List<dynamic>' is not a subtype of type 'List<String>'

Quick Answer

A List<dynamic> from JSON was assigned to a typed List<String> variable.

Why This Happens

In Dart, JSON decoding produces List<dynamic> and Map<String, dynamic>. Assigning these directly to typed collections fails because Dart's type system is strict. Use .cast<T>() or .map() to convert the dynamic list to the expected type.

The Problem

final json = jsonDecode(response.body);
final List<String> names = json['names']; // List<dynamic> != List<String>

The Fix

final json = jsonDecode(response.body);
final List<String> names = List<String>.from(json['names']);

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error message: type 'List<dynamic>' is not a subtype of type 'List<String>'. This is a type mismatch from JSON parsing.

  2. 2

    Find the cause

    Check where JSON data is decoded and assigned to typed collections without explicit casting.

  3. 3

    Apply the fix

    Use List<T>.from() or .cast<T>() to explicitly convert the dynamic list to the expected type.

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