Dart: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>' in type cast
JSON decoded to a Map but your code expected a List (or the other way round).
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>'type '_Map<String, dynamic>' is not a subtype of type 'List<dynamic>' in type castis not a subtype of type 'List<dynamic>'type 'String' is not a subtype of type 'int' of 'index' Meaning
jsonDecode returns a Map for {…} and a List for […]. APIs often wrap lists in an object ({"data": […]}), or return an error object on failure. Print response.body, then read the right key before casting.
Common causes
- Response is an object with a wrapper key, not a bare array
- Error JSON returned instead of the list
- Pagination envelope (
items,results) - Casting
as Liston a Map - Mismatched model for single vs list endpoint
⚡ Quick fix
- Log
response.bodyfirst - Read the wrapper key:
jsonDecode(body)['data'] as List - Check
response.statusCodebefore decoding
Detailed fix by platform
Dart
final decoded = jsonDecode(body); final list = decoded is List ? decoded : decoded['items'] as List;
How to diagnose
- Body — Object or array?
- Status — 200?
- Key — Wrapper name?
🔧 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
- Error: Couldn't resolve the package Dart: Error: Couldn't resolve the package 'x' in 'package:x/x.dart'
- FormatException: Unexpected character Dart: FormatException: Unexpected character (at character 1) <!DOCTYPE html> — jsonDecode of an HTML page
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
- Null check operator used on a null value Dart/Flutter: Null check operator used on a null value
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