Short answer
Convert the list instead of casting it: List<int>.from(json['ids']) or (json['ids'] as List).cast<int>(). For lists of objects, map each element: (json['items'] as List).map((e) => Item.fromJson(e as Map<String, dynamic>)).toList().
Why the list has the wrong type, and the fix
01
A JSON list assigned to a typed list
“The elements iterable itself may have any element type, so this constructor can be used to down-cast a List” Dart, List.from constructor
final List<int> ids = json['ids']; compiles but fails at runtime. List.from creates a new list of the right type and checks every element.
final ids = List<int>.from(json['ids'] as List); final tags = List<String>.from(json['tags'] ?? const []);02
A list of objects
Each element is a Map<String, dynamic>, so convert each one into your model with map and toList.
final items = (json['items'] as List) .map((e) => Item.fromJson(e as Map<String, dynamic>)) .toList();03
cast<int>() and mixed numbers
“If any operation tries to read an element that is not an instance of R, the access will throw instead.” Dart, List.cast
cast<int>() returns a typed view without copying. It throws when an element isn’t an int, which happens when the API sends 1.0 or a string. Normalize those first: for 1.0, use (e as num).toInt(); for numeric strings, use int.parse(e as String).
final counts = (json['counts'] as List).map((e) => (e as num).toInt()).toList();
Checked against the vendor’s docs on : Dart API: List.from; Dart API: List.cast; Flutter: JSON and serialization.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Flutter “Map is not a subtype of type List” · Flutter “type ‘Null’ is not a subtype of type ‘String’” · Flutter “String can’t be assigned to Uri” · Flutter “Looking up a deactivated widget’s ancestor is unsafe”