This question is almost identical to the one answered here The difference is that my data is json, coming from an API call. This is causing the error shown at the bottom of the code below. I've tried various combinations of casting and variable types with no success.
import 'dart:convert';
import "package:collection/collection.dart";
void main(List<String> args) {
var data1 = [
{"title": 'Avengers', "release_date": '10/01/2019'},
{"title": 'Creed', "release_date": '10/01/2019'},
{"title": 'Jumanji', "release_date": '30/10/2019'},
];
//without these two lines, the code executes with no problems
var data2 = jsonEncode(data1);
var data3 = jsonDecode(data2);
try {
var newMap = groupBy(data3, (Map obj) => obj['release_date']);
print(newMap);
} catch (err) {
print(err);
}
**type 'List<dynamic>' is not a subtype of type 'Iterable<Map<dynamic, dynamic>>'**
[1]: https://stackoverflow.com/a/54036449/3185563