|
1 | 1 | # SKGenerateModelTool
|
2 | 2 |
|
| 3 | +# SKGenerateModelTool |
| 4 | + |
3 | 5 |
|
4 | 6 | 
|
5 | 7 |
|
| 8 | +- 支持Objective-C / Swift / Dart |
6 | 9 | - 支持通过URL链接或json字符串一键生成model文件
|
7 | 10 | - 支持字符串加密(可设置不同的密钥,开发者可自行修改加密算法)
|
8 | 11 | - 支持自定义model父类、自定义model前缀、自定义文件名、自定义作者名
|
9 |
| -- 支持OC / Swift |
10 | 12 | - 支持自定义输出文件夹路径
|
11 | 13 | - 兼容YYModel / MJExtension / HandyJSON解析
|
12 | 14 | - 兼容服务端返回“id”字段
|
13 |
| -- 支持类驼峰命名 |
| 15 | +- 类驼峰命名 |
14 | 16 |
|
| 17 | +- Support OC / Swift / Dart |
15 | 18 | - Supports one-click generation of model files through URL links or json strings
|
16 | 19 | - Support string encryption (different keys can be set, developers can modify the encryption algorithm)
|
17 | 20 | - Support custom model parent class, custom model prefix, custom file name, custom author name
|
18 |
| -- Support OC / Swift |
19 | 21 | - Support custom output folder path
|
20 | 22 | - Compatible with YYModel / MJExtension analysis
|
21 | 23 | - Compatible server returns "id" field
|
22 | 24 | - Supports hump naming
|
23 | 25 |
|
| 26 | +###### 生成Flutter Dart Model |
| 27 | + |
| 28 | +``` |
| 29 | +// |
| 30 | +// news_response.dart |
| 31 | +// SKGenerateModelTool |
| 32 | +// |
| 33 | +// Created by wushangkun on 2021/01/29. |
| 34 | +// Copyright © 2021 SKGenerateModelTool. All rights reserved. |
| 35 | +// |
| 36 | +
|
| 37 | +part 'news_response.m.dart'; |
| 38 | +
|
| 39 | +class NewsResponse extends NSObject { |
| 40 | + List<SKDataModel> data; |
| 41 | + String msg; // success |
| 42 | + int code; // 200 |
| 43 | +
|
| 44 | + NewsResponse fromJson(Map<String, dynamic> json) => _$NewsResponseFromJson(json, this); |
| 45 | + Map<String, dynamic> toJson() => _$NewsResponseToJson(this); |
| 46 | +} |
| 47 | +
|
| 48 | +class SKDataModel extends NSObject { |
| 49 | + String title; |
| 50 | + String source; // 环球网资讯 |
| 51 | + String imgsrc; |
| 52 | +
|
| 53 | + SKDataModel fromJson(Map<String, dynamic> json) => _$SKDataModelFromJson(json, this); |
| 54 | + Map<String, dynamic> toJson() => _$SKDataModelToJson(this); |
| 55 | +} |
| 56 | +
|
| 57 | +``` |
| 58 | + |
| 59 | +实现文件 |
| 60 | + |
| 61 | +``` |
| 62 | +// |
| 63 | +// news_response.m.dart |
| 64 | +// SKGenerateModelTool |
| 65 | +// |
| 66 | +// Created by wushangkun on 2021/01/29. |
| 67 | +// Copyright © 2021 SKGenerateModelTool. All rights reserved. |
| 68 | +// |
| 69 | +
|
| 70 | +part of 'news_response.dart'; |
| 71 | +
|
| 72 | +NewsResponse _$NewsResponseFromJson(Map<String, dynamic> json, NewsResponse instance) { |
| 73 | + if(json['data'] != null) { |
| 74 | + instance.data = new List<SKDataModel>(); |
| 75 | + (json['data'] as List).forEach((v) { |
| 76 | + instance.data.add(new SKDataModel().fromJson(v)); |
| 77 | + }); |
| 78 | + } |
| 79 | + if(json['msg'] != null) { |
| 80 | + instance.msg = json['msg']?.toString(); |
| 81 | + } |
| 82 | + if(json['code'] != null) { |
| 83 | + final code = json['code']; |
| 84 | + if(code is String) { |
| 85 | + instance.code = int.parse(code); |
| 86 | + } else { |
| 87 | + instance.code = code?.toInt(); |
| 88 | + } |
| 89 | + } |
| 90 | + return instance; |
| 91 | +} |
| 92 | +
|
| 93 | +Map<String, dynamic> _$NewsResponseToJson(NewsResponse instance) { |
| 94 | + final Map<String, dynamic> json = new Map<String, dynamic>(); |
| 95 | + if(instance.data != null) { |
| 96 | + json['data'] = instance.data.map((v) => v.toJson()).toList(); |
| 97 | + } |
| 98 | + json['msg'] = instance.msg; |
| 99 | + json['code'] = instance.code; |
| 100 | + return json; |
| 101 | +} |
| 102 | +
|
| 103 | +SKDataModel _$SKDataModelFromJson(Map<String, dynamic> json, SKDataModel instance) { |
| 104 | + if(json['title'] != null) { |
| 105 | + instance.title = json['title']?.toString(); |
| 106 | + } |
| 107 | + if(json['source'] != null) { |
| 108 | + instance.source = json['source']?.toString(); |
| 109 | + } |
| 110 | + if(json['imgsrc'] != null) { |
| 111 | + instance.imgsrc = json['imgsrc']?.toString(); |
| 112 | + } |
| 113 | + return instance; |
| 114 | +} |
| 115 | +
|
| 116 | +Map<String, dynamic> _$SKDataModelToJson(SKDataModel instance) { |
| 117 | + final Map<String, dynamic> json = new Map<String, dynamic>(); |
| 118 | + json['title'] = instance.title; |
| 119 | + json['source'] = instance.source; |
| 120 | + json['imgsrc'] = instance.imgsrc; |
| 121 | + return json; |
| 122 | +} |
| 123 | +
|
| 124 | +``` |
24 | 125 |
|
25 | 126 | ###### 生成Model
|
26 | 127 | 
|
|
0 commit comments