我正在尝试通过id(来自tmdb)获取详细信息
Stream<DetailsTv> getDetailsTv(int id) async* {
http.Response response =
await http.get('$mainUrl/tv/$id?api_key=$apiKey&language=en-US');
yield DetailsTv.fromJson(jsonDecode(response.body));
}
StreamBuilder<DetailsTv>(
stream: stream.getDetailsTv(id),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Container(
child: Text(snapshot.data.name),
);
}
else if (snapshot.hasError) {
return Center(
child: Text(snapshot.error.toString()),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
}),
但是我得到这个错误 类型“ double”不是类型“ int”的子类型 但是id是int
答案 0 :(得分:0)
stream.getDetailsTv(int.parse(id.toString()))
确保将id转换为int