使用 Flutter 模型和动态 api 响应

问题描述 投票:0回答:0
大家好,我是 flutter 的新手 我通过在线工具为我的历史生成了一个模型类 我的问题是将我的模型的响应作为 listviwe 应用到我的 main.dark class History { String ?日期;列表

?细节;历史({this.date,this.detail}); History.fromJson(Map < Detail > json) { date = json['date']; if (json['detail'] != null) { detail = < String, dynamic >[]; json['detail'].forEach((v) { detail!.add(new Detail.fromJson(v)); }); } } Map toJson() { final Map data = new Map();数据['日期'] = this.date; if (this.detail != null) { data['detail'] = this.detail!.map((v) => v.toJson()).toList(); } 返回数据; } } 类详细信息 { 字符串? ID;细绳?日期Trx;无效的?用户;细绳?价格;无效的?产品编号;细绳?数量;细节({this.id,this.dateTrx,this.user,this.price,this.productId,this.quantity}); Detail.fromJson(Map json) { id = json['id']; dateTrx = json['date_trx'];用户 = json['用户'];价格 = json['价格']; productId = json['product_id'];数量 = json['数量']; } Map toJson() { final Map data = new Map();数据['id'] = this.id;数据['date_trx'] = this.dateTrx;数据['用户'] = this.user;数据['价格'] = this.price; data['product_id'] = this.productId;数据['数量'] = this.quantity;返回数据; } }

flutter api listview dynamic model
© www.soinside.com 2019 - 2024. All rights reserved.