forked from lxm_flutter/json2dart
Compare commits
2 Commits
v1.0.5
...
replace-fa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8f7b637a3 | ||
|
|
88a48be157 |
@@ -46,14 +46,18 @@ class Generator {
|
||||
var fieldList = template.fieldList;
|
||||
fieldList.forEach((filed) {
|
||||
if (filed is MapField) {
|
||||
DefaultTemplate template = DefaultTemplate(
|
||||
srcJson: json.encode(filed.map), className: filed.typeString);
|
||||
DefaultTemplate template = DefaultTemplate(srcJson: json.encode(filed.map), className: filed.typeString);
|
||||
if (version == Version.v1) {
|
||||
template = V1Template(srcJson: json.encode(filed.map), className: filed.typeString);
|
||||
}
|
||||
templateList.add(template);
|
||||
refreshTemplate(template);
|
||||
} else if (filed is ListField) {
|
||||
if (filed.childIsObject) {
|
||||
DefaultTemplate template = DefaultTemplate(
|
||||
srcJson: json.encode(filed.list[0]), className: filed.typeName);
|
||||
DefaultTemplate template = DefaultTemplate(srcJson: json.encode(filed.list[0]), className: filed.typeName);
|
||||
if (version == Version.v1) {
|
||||
template = V1Template(srcJson: json.encode(filed.list[0]), className: filed.typeName);
|
||||
}
|
||||
templateList.add(template);
|
||||
refreshTemplate(template);
|
||||
}
|
||||
@@ -63,8 +67,7 @@ class Generator {
|
||||
|
||||
String get fileName => camelCase2UnderScoreCase(entityName);
|
||||
|
||||
static const String importString =
|
||||
"import 'package:json_annotation/json_annotation.dart';";
|
||||
static const String importString = "import 'package:json_annotation/json_annotation.dart';";
|
||||
|
||||
String get header => """$importString
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ String entityName = null;
|
||||
bool useJsonKey = true;
|
||||
|
||||
bool isCamelCase = true;
|
||||
bool isStaticMethod = true;
|
||||
|
||||
var downloadFileName = "";
|
||||
|
||||
@@ -61,6 +62,7 @@ void main() async {
|
||||
|
||||
InputElement eJsonKey = querySelector("#use_json_key");
|
||||
InputElement eCamelCase = querySelector("#camelCase");
|
||||
InputElement eUseStatic = querySelector("#use_static");
|
||||
TextAreaElement result = querySelector("#result");
|
||||
RadioButtonInputElement v0 = querySelector("#v0");
|
||||
RadioButtonInputElement v1 = querySelector("#v1");
|
||||
@@ -125,6 +127,17 @@ void main() async {
|
||||
refreshData();
|
||||
});
|
||||
|
||||
eUseStatic.checked = isStaticMethod;
|
||||
eUseStatic.onInput.listen((event) {
|
||||
isStaticMethod = eUseStatic.checked;
|
||||
refreshData();
|
||||
});
|
||||
|
||||
querySelector("#useStaticLabel").onClick.listen((event) {
|
||||
eUseStatic.checked = !eUseStatic.checked;
|
||||
refreshData();
|
||||
});
|
||||
|
||||
refreshData();
|
||||
|
||||
querySelector("#copy").onClick.listen((event) {
|
||||
|
||||
@@ -97,6 +97,9 @@ class DefaultTemplate extends Template {
|
||||
|
||||
@override
|
||||
String method() {
|
||||
if (main.isStaticMethod) {
|
||||
return " static $className fromJson(Map<String, dynamic> srcJson) => _\$${className}FromJson(srcJson);";
|
||||
}
|
||||
return " factory $className.fromJson(Map<String, dynamic> srcJson) => _\$${className}FromJson(srcJson);";
|
||||
}
|
||||
|
||||
|
||||
11
pubspec.yaml
11
pubspec.yaml
@@ -11,11 +11,10 @@ environment:
|
||||
# path: ^1.4.1
|
||||
dependencies:
|
||||
# Your other regular dependencies here
|
||||
json_annotation: ^0.2.3
|
||||
intl: ^0.15.7
|
||||
json_annotation: ^3.0.0
|
||||
intl: ^0.15.8
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^0.9.0
|
||||
build_web_compilers: ^0.4.0
|
||||
json_serializable: ^0.5.4
|
||||
build_runner: ^1.6.6
|
||||
build_web_compilers: ^2.2.3
|
||||
json_serializable: ^3.2.0
|
||||
@@ -40,6 +40,8 @@
|
||||
<span id="check_label">jsonKey annotation</span>
|
||||
<input type="checkbox" id="camelCase" />
|
||||
<span id="camelCaseLabel">use camelCase</span>
|
||||
<input type="checkbox" id="use_static" />
|
||||
<span id="useStaticLabel">use static</span>
|
||||
</div>
|
||||
<div id="file_name"></div>
|
||||
</span>
|
||||
|
||||
@@ -38,9 +38,11 @@
|
||||
类名称
|
||||
<input id="out_entity_name" />
|
||||
<input type="checkbox" id="use_json_key" />
|
||||
<span id="check_label">jsonKey annotation</span>
|
||||
<span id="check_label">使用 JsonKey 注解</span>
|
||||
<input type="checkbox" id="camelCase" />
|
||||
<span id="camelCaseLabel">use camelCase</span>
|
||||
<span id="camelCaseLabel">驼峰命名</span>
|
||||
<input type="checkbox" id="use_static" />
|
||||
<span id="useStaticLabel">使用静态方法</span>
|
||||
</div>
|
||||
<div id="file_name"></div>
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user