【发布时间】:2021-06-09 03:41:21
【问题描述】:
我正在尝试从如下所示的服务器获取数据:
[
{
"key": "value",
"key": "value",
"key": "value",
"key": "value",
"key": [
"key": "value",
"key": "value",
],
"key": "value",
"key": "value",
}
]
我的模型类有这个: 更新:
List<VehicleDetails> vehicleDetailsFromJson(String str) => List<VehicleDetails>.from(json.decode(str).map((x) => VehicleDetails.fromJson(x)));
factory ModelClassName.fromJson(Map<String, dynamic> json) => ModelClassName()
我的服务类有这个:更新:
Future<List<ModelClassName>> fetchDetails() async{
final response = await get(Uri.parse('$url'),
headers: {
'Authorization': "bearer _accessToken",
'Content-Type': 'application/json'
},);
return modelClassFromJson(response.body);
}
我正在使用 FutureBuilder() 来获取和更新我的屏幕
FutureBuilder(
future: fetchDetails(),
builder: (_, snapshot) {
print(snapshot.error);
if(snapshot.connectionState == ConnectionState.done)
return Widget();
else
return Center(
child: CircularProgressIndicator(),
);
},
),
我得到的错误:
type 'double' 不是 type 'int' 的子类型
我该如何度过这个难关?请帮忙。
【问题讨论】:
-
jsonData是List<Map<String, dyanmic>>,因为 JSON 响应以[开头。这表明它是一个 JSON 数组。
标签: flutter dart flutter-futurebuilder