Super Flutter Util
该插件是 flutter 的辅助扩展,已添加的功能:
一、从剪切板获取 json 数据并转为 dart 数据模型
目前支持右键文件夹或右键代码编辑器添加模型
,将会从剪切板中提取json数据,所有参数都为必填且非空:
{
"title": "string",
"age": 0,
"duration": 10.1,
"info": {
"address": "string",
"email": "string"
},
"phones": ["string"],
"companys": [
{
"name": "string",
"address": "string"
}
]
}
转换后:
class TestModel {
String title;
int age;
double duration;
TestModelInfo info;
List<TestModelCompanysItem> companys;
TestModel({
required this.title,
required this.age,
required this.duration,
required this.info,
required this.companys,
});
factory TestModel.fromJson(dynamic json) {
if (json is! Map) json = <dynamic, dynamic>{};
return TestModel(
title: json['title'] is String ? json['title'] : '',
age: json['age'] is int ? json['age'] : 0,
duration: json['duration'] is double ? json['duration'] : 0,
info: TestModelInfo.fromJson(json['info']),
companys: json['companys'] is List ? json['companys'].map<TestModelCompanysItem>((item) => TestModelCompanysItem.fromJson(item)).toList() : [],
);
}
Map<String, dynamic> toJson() => {
'title': title,
'age': age,
'duration': duration,
'info': info.toJson(),
'companys': companys.map((item) => item.toJson()).toList(),
};
}
class TestModelInfo ...
class TestModelCompanysItem ...