输入“列表<动态>”不是'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 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>();
类型没有具体的泛型类型。
genreIds
需要 List< int>
而不是 List
(或 List< dynamic>
),因此在分配值之前,您需要将该值带入所需的类型。
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
成为默认值(以前是选择加入的)
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屋!