首先自己写好模型类模板代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| import 'package:json_annotation/json_annotation.dart'; part 'buy_record_data.g.dart';
@JsonSerializable() class BuyRecordData { List<BuyRecordEntity> entities; BuyRecordData(this.entities); factory BuyRecordData.fromJson(Map<String, dynamic> json) => _$BuyRecordDataFromJson(json); Map<String, dynamic> toJson() => _$BuyRecordDataToJson(this); }
|
然后在终端运行,生成.g.dart文件
1 2
| flutter packages pub run build_runner build --delete-conflicting-outputs
|
参考:1. https://blog.csdn.net/YoYo_Newbie/article/details/90634878?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control
- https://my.oschina.net/u/4326108/blog/3675231