我有来自 api 的数据,如下所示:
{
"status": true,
"error": "",
"message": "Record Found.",
"data": {
"2021-Apr-19": [
{
"img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
"person": "CooperMac",
"message": " supported your activity drawing."
}
],
"2021-Mar-30": [
{
"img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
"person": "CooperMac",
"message": " commented on your activity Test Activity 12-11-2020."
},
{
"img_url": "https://www.rezzap.com/uploads/profile-photo/BWPOFCyHMFm_OgzvCxRwS5dBJTS6wCgy.jpg",
"person": "CooperMac",
"message": " supported your activity ."
},
],
}
}
同样,我制作了这样的模型-:
class Support {
Support({
this.data,
});
Map<String, List<Datum>> data;
factory Support.fromJson(Map<String, dynamic> json) => Support(
data: Map.from(json["data"]).map((k, v) =>
MapEntry<String, List<Datum>>(
k, List<Datum>.from(v.map((x) => Datum.fromJson(x))))),
);
}
class Datum {
Datum({
this.imgUrl,
this.person,
this.message,
});
String imgUrl;
String person;
String message;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
imgUrl: json["img_url"],
person: json["person"],
message: json["message"],
);
}
这是回应但我不知道如何在模型中解析它,我需要在这里更正,所以如果有人可以提供帮助
Future<Support> getSupportActivityData() async {
final response = await _helper.get(supportedActivityUrl);
var responseData = response["data"];
var list = responseData as Map<String, dynamic>;
return Support.fromJson(list);
}
我也尝试将返回类型设为“Future<Map<String, List>>”等,但它总是向我显示类型转换错误
我想获取该数据并将其显示为List,那么我如何在这个分组的 List 中显示它,因为它要求键作为 Header 并且值作为它的行?