我尝试从API提取数据,并且其他一些数据正确提取,但不是图像。图片未显示我该如何解决?
这是我的模特
class Album {
final int temp;
final int hum, pres, clouds;
final String msg, cityname;
List<String> weatherDescriptions;
List<String> weatherIcons;
Album(
{this.weatherDescriptions,
this.temp,
this.cityname,
this.clouds,
this.hum,
this.weatherIcons,
this.msg,
this.pres});
factory Album.fromJson(Map<String, dynamic> json) {
return Album(
weatherDescriptions: List<String>.from(
json['current']["weather_descriptions"].map((x) => x)),
temp: json['current']['temperature'],
cityname: json['request']['query'],
// desc: json['weather'][0]['description']
);
}
Map<String, dynamic> toJson() => {
"weather_descriptions":
List<dynamic>.from(weatherDescriptions.map((x) => x)),
};
}
这是我的代码
FutureBuilder<Album>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Container(
child: Column(
children: <Widget>[
Text("${snapshot.data.cityname}"),
Text("${snapshot.data.temp}"),
Text("${snapshot.data.weatherDescriptions.join(',')}"),
Image.network("${snapshot.data.weatherIcons}"),
],
),
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
},
),
答案 0 :(得分:0)
您没有在任何地方显示图像。您可以使用Image.network
(Docs)从网络加载图像。您需要将图像的路径添加到数据结构中。
请检查您尝试获取的URL(存储在snapshot.data.weatherIcons
中)是否实际可访问。您可以在您选择的浏览器中打开它。如果您看到该图片或得到下载提示,我们可以继续执行下一步。