I've just switched my linter in VSCode from Pedantic to Lint, and half of my app lit up. Most of it is easy to fix except for a string of Type assignment errors. The following code taken mostly from examples gives the following error:
"The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>'".
static List<Treatment> decodeData(String treatments) =>
(jsonDecode(treatments) as List<dynamic>)
.map<Treatment>((item) => Treatment.fromJson(item))
.toList();
Can anyone point me in the right direction? Thanks
Try adding .cast<Map<String, dynamic>>()
, like so:
static List<Treatment> decodeData(String treatments) =>
(jsonDecode(treatments) as List<dynamic>)
.cast<Map<String, dynamic>>()
.map<Treatment>((item) => Treatment.fromJson(item))
.toList();
You can try casting it at the end
static List<Treatment> decodeData(String treatments) =>
(jsonDecode(treatments) as List<dynamic>)
.map<Treatment>((item) => Treatment.fromJson(item))
.toList() as Map<String, dynamic>;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.