输入'列表<动态>'不是“List<int>"类型的子类型在哪里 [英] type 'List<dynamic>' is not a subtype of type 'List<int>' where
问题描述
我是 Flutter 的新手,我尝试运行一个 GitHub 项目,但遇到了一个错误,比如 List dynamic 不是 List int 类型的子类型.Github 链接
I am new to Flutter, I try to run one GitHub project but got an error like type List dynamic is not a subtype of type List int where. Github Link
错误行
List<int> genreIds;
MediaItem._internalFromJson(Map jsonMap, {MediaType type: MediaType.movie})
:
type = type,
id = jsonMap["id"].toInt(),
voteAverage = jsonMap["vote_average"].toDouble(),
title = jsonMap[(type == MediaType.movie ? "title" : "name")],
posterPath = jsonMap["poster_path"] ?? "",
backdropPath = jsonMap["backdrop_path"] ?? "",
overview = jsonMap["overview"],
releaseDate = jsonMap[(type == MediaType.movie
? "release_date"
: "first_air_date")],
genreIds = jsonMap["genre_ids"];//in this line
}
任何帮助将不胜感激,在此先感谢您.
Any help will be appreciated, thank you in advance.
推荐答案
更改
genreIds = jsonMap["genre_ids"];
到
genreIds = jsonMap["genre_ids"].cast<int>();
JSON 映射或列表中的类型没有具体的泛型类型.genreIds
需要 List
而不是 List
(或 List
),因此您需要将值设为所需的类型,然后才能对其进行赋值.
types in JSON maps or lists don't have concrete generic types.
genreIds
requires a List<int>
not a List
(or List<dynamic>
), therefore you need to bring the value to its required type before you can assign it.
如果您之前没有看到相同代码的此错误,那么可能是因为您升级到了 Dart 版本,其中 --preview-dart-2
成为默认值(它是 opt-在以前)
If you haven't seen this error earlier for the same code, then it's probably because you upgraded to a Dart version where --preview-dart-2
became the default (it was opt-in previously)
这篇关于输入'列表<动态>'不是“List<int>"类型的子类型在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!