_CastError (type 'List<dynamic>' is not a subtype of type 'List<int>' in type cast)
I receive this error when attempting to decode a json string back into the list of objects from which it was created. I don't understand why it struggles to cast this; the underlying dynamic type is clearly an integer. Here is the code below, edited to be more concisely related to the issue.
class Obj extends Equatable {
final List<int> scheduledTimes;
final bool active;
...
Obj.fromJson(Map<String, dynamic> json)
: scheduledTimes = json['scheduledTimes'] as List<int>,
active = json['active'] as bool;
Map<String, dynamic> toJson() {
Map<String, dynamic> map = {};
map['scheduledTimes'] = scheduledTimes;
map['active'] = active;
return map;
}
...
I encoded this using json.encode
(which triggered toJson()) and then immediately attempted to json.decode
this but it failed with the error:
_CastError (type 'List<dynamic>' is not a subtype of type 'List<int>' in type cast)