Skip to content

Commit

Permalink
build with flutter 3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
zmtzawqlp committed Aug 30, 2022
1 parent e04006f commit d2dd34d
Show file tree
Hide file tree
Showing 48 changed files with 440 additions and 305 deletions.
41 changes: 38 additions & 3 deletions Flutter/json_to_dart/.metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: b939921663e461cea3061e130a26f40cbb8059e0
channel: master
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: android
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: ios
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: linux
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: macos
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: web
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: windows
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
4 changes: 3 additions & 1 deletion Flutter/json_to_dart/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"dart.flutterSdkPath": "/Users/zmt/Documents/flutter/3.0.0"
}
3 changes: 2 additions & 1 deletion Flutter/json_to_dart/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"automaticCheck":"Automatic Check",
"buttonCopyText":"Copy",
"buttonCopySuccess":"Copy Success",
"resultDialogTitle":"Result"
"resultDialogTitle":"Result",
"showResultDialog":"show result dialog"
}
3 changes: 2 additions & 1 deletion Flutter/json_to_dart/lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"automaticCheck":"自动校验",
"buttonCopyText":"复制",
"buttonCopySuccess":"复制成功",
"resultDialogTitle":"结果"
"resultDialogTitle":"结果",
"showResultDialog":"显示结果弹框"
}
3 changes: 2 additions & 1 deletion Flutter/json_to_dart/lib/l10n/app_zh_Hant.arb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@
"automaticCheck":"自動校驗",
"buttonCopyText":"複製",
"buttonCopySuccess":"複製成功",
"resultDialogTitle":"結果"
"resultDialogTitle":"結果",
"showResultDialog":"顯示結果彈框"
}
22 changes: 14 additions & 8 deletions Flutter/json_to_dart/lib/main_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import 'models/config.dart';
import 'models/dart_object.dart';

void showAlertDialog(String msg, [IconData data = Icons.warning]) {
SmartDialog.show(
SmartDialog.compatible.show(
widget: AlertDialog(
title: Icon(data),
content: Text(msg),
actions: <Widget>[
TextButton(
child: Text(appLocalizations.ok),
onPressed: () {
SmartDialog.dismiss();
SmartDialog.compatible.dismiss();
},
),
],
Expand Down Expand Up @@ -60,7 +60,7 @@ class MainController extends GetxController {
return;
}

SmartDialog.showLoading(
SmartDialog.compatible.showLoading(
widget: const Center(
child: SpinKitCubeGrid(color: Colors.orange),
));
Expand All @@ -85,17 +85,23 @@ class MainController extends GetxController {
// handleError(error, stackTrace);
// });
if (extendedObject == null) {
SmartDialog.dismiss();
SmartDialog.compatible.dismiss();
showAlertDialog(appLocalizations.illegalJson, Icons.error);
return;
}

dartObject = extendedObject;
if (ConfigSetting().nullsafety.value &&
ConfigSetting().nullable.value &&
!ConfigSetting().smartNullable.value) {
updateNullable(true);
}

final String? formatJsonString =
await compute<dynamic, String?>(formatJson, jsonData)
.onError((Object? error, StackTrace stackTrace) {
handleError(error, stackTrace);
return null;
});
if (formatJsonString != null) {
_textEditingController.text = formatJsonString;
Expand All @@ -105,7 +111,7 @@ class MainController extends GetxController {
} catch (error, stackTrace) {
handleError(error, stackTrace);
}
SmartDialog.dismiss();
SmartDialog.compatible.dismiss();
}

String? generateDart() {
Expand Down Expand Up @@ -169,16 +175,16 @@ class MainController extends GetxController {
if (ConfigSetting().addMethod.value) {
if (ConfigSetting().enableArrayProtection.value) {
sb.writeLine('import \'dart:developer\';');
sb.writeLine(ConfigSetting().nullsafety
sb.writeLine(ConfigSetting().nullsafety.value
? DartHelper.tryCatchMethodNullSafety
: DartHelper.tryCatchMethod);
}

sb.writeLine(ConfigSetting().enableDataProtection.value
? ConfigSetting().nullsafety
? ConfigSetting().nullsafety.value
? DartHelper.asTMethodWithDataProtectionNullSafety
: DartHelper.asTMethodWithDataProtection
: ConfigSetting().nullsafety
: ConfigSetting().nullsafety.value
? DartHelper.asTMethodNullSafety
: DartHelper.asTMethod);
}
Expand Down
19 changes: 10 additions & 9 deletions Flutter/json_to_dart/lib/models/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,27 @@ class ConfigSetting extends Setting<ConfigSetting> {
Rx<PropertyNameSortingType> propertyNameSortingType =
PropertyNameSortingType.none.obs;

@HiveField(10, defaultValue: false)
bool nullsafety = false;
RxBool nullsafetyObs = false.obs;
@HiveField(16)
RxBool nullsafety = false.obs;

@HiveField(11, defaultValue: true)
bool nullable = true;
RxBool nullableObs = true.obs;
@HiveField(17)
RxBool nullable = true.obs;

@HiveField(12)
Rx<Locale> locale = const Locale.fromSubtags(languageCode: 'en').obs;

@HiveField(13, defaultValue: false)
bool smartNullable = false;
RxBool smartNullableObs = false.obs;
@HiveField(18)
RxBool smartNullable = false.obs;

@HiveField(14)
RxBool addCopyMethod = false.obs;

@HiveField(15)
RxBool automaticCheck = true.obs;

@HiveField(19)
RxBool showResultDialog = true.obs;

@override
Future<void> init({
TypeAdapter<ConfigSetting>? adapter,
Expand Down
30 changes: 16 additions & 14 deletions Flutter/json_to_dart/lib/models/config.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions Flutter/json_to_dart/lib/models/dart_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class DartObject extends DartProperty {
data: arrayItem,
type: DartHelper.converDartType(arrayItem.runtimeType),
nullable: DartHelper.converNullable(value) &&
ConfigSetting().smartNullable)),
ConfigSetting().smartNullable.value)),
depth,
addProperty: false);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ class DartObject extends DartProperty {
if (other != null) {
_mergeObject ??= <String, _InnerObject>{};

if (ConfigSetting().smartNullable) {
if (ConfigSetting().smartNullable.value) {
for (final MapEntry<String, _InnerObject> existObject
in _mergeObject!.entries) {
if (!other.containsKey(existObject.key)) {
Expand Down Expand Up @@ -202,7 +202,7 @@ class DartObject extends DartProperty {
? item.value.type
: existObject.type,
nullable: (existObject.nullable || item.value.nullable) &&
ConfigSetting().smartNullable);
ConfigSetting().smartNullable.value);
_mergeObject![item.key] = existObject;
needInitialize = true;
} else if (existObject.isList &&
Expand Down Expand Up @@ -338,8 +338,8 @@ class DartObject extends DartProperty {
String setString = '';
final String fss = DartHelper.factorySetString(
item.propertyAccessorType.value,
(!ConfigSetting().nullsafety) ||
(ConfigSetting().nullsafety && item.nullable),
(!ConfigSetting().nullsafety.value) ||
(ConfigSetting().nullsafety.value && item.nullable),
);
final bool isGetSet = fss.startsWith('{');
String copyProperty = item.name.value;
Expand All @@ -351,19 +351,19 @@ class DartObject extends DartProperty {
item.name.value,
item.key,
className,
if (ConfigSetting().nullsafety && item.nullable)
if (ConfigSetting().nullsafety.value && item.nullable)
'${DartHelper.jsonRes}[\'${item.key}\']==null?null:'
else
'',
if (ConfigSetting().nullsafety) '!' else ''
if (ConfigSetting().nullsafety.value) '!' else ''
]);
typeString = className;
if (ConfigSetting().nullsafety && item.nullable) {
if (ConfigSetting().nullsafety.value && item.nullable) {
typeString += '?';
}

if (ConfigSetting().addCopyMethod.value) {
if (!ConfigSetting().nullsafety || item.nullable) {
if (!ConfigSetting().nullsafety.value || item.nullable) {
copyProperty += '?';
}
copyProperty += '.copy()';
Expand All @@ -387,7 +387,7 @@ class DartObject extends DartProperty {

setString = ' ${item.name}:$lowName';

if (ConfigSetting().nullsafety) {
if (ConfigSetting().nullsafety.value) {
if (item.nullable) {
typeString += '?';
} else {
Expand Down Expand Up @@ -461,7 +461,7 @@ class DartObject extends DartProperty {
String fromJson = '';
if (fromJsonSb1.length != 0) {
fromJson = stringFormat(
ConfigSetting().nullsafety
ConfigSetting().nullsafety.value
? DartHelper.fromJsonHeader1NullSafety
: DartHelper.fromJsonHeader1,
<String>[className.value]) +
Expand All @@ -470,7 +470,7 @@ class DartObject extends DartProperty {
<String>[className.value, fromJsonSb.toString()]);
} else {
fromJson = stringFormat(
ConfigSetting().nullsafety
ConfigSetting().nullsafety.value
? DartHelper.fromJsonHeaderNullSafety
: DartHelper.fromJsonHeader,
<String>[className.value]) +
Expand Down Expand Up @@ -524,6 +524,7 @@ class _InnerObject {
});
final dynamic data;
final DartType type;
// data is null ?
final bool nullable;

bool get isList => data is List;
Expand Down
8 changes: 4 additions & 4 deletions Flutter/json_to_dart/lib/models/dart_property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ class DartProperty extends Equatable {
]);
copy = copy.replaceFirst(
'e',
ConfigSetting().nullsafety && !nullable ? name.value : name + '?',
ConfigSetting().nullsafety.value && !nullable ? name.value : name + '?',
);

if (!ConfigSetting().nullsafety) {
if (!ConfigSetting().nullsafety.value) {
copy = copy.replaceRange(
copy.length - '.toList()'.length, null, '?.toList()');
}
Expand Down Expand Up @@ -199,10 +199,10 @@ class DartProperty extends Equatable {
dynamic temp = value;
final MyStringBuffer sb = MyStringBuffer();
sb.writeLine(
" final ${ConfigSetting().nullsafety ? typeString + '?' : typeString} $setName = ${DartHelper.jsonRes}['$key'] is List ? ${typeString.substring('List'.length).replaceAll('?', '')}[]: null; ");
" final ${ConfigSetting().nullsafety.value ? typeString + '?' : typeString} $setName = ${DartHelper.jsonRes}['$key'] is List ? ${typeString.substring('List'.length).replaceAll('?', '')}[]: null; ");
sb.writeLine(' if($setName!=null) {');
final bool enableTryCatch = ConfigSetting().enableArrayProtection.value;
final String nonNullable = ConfigSetting().nullsafety ? '!' : '';
final String nonNullable = ConfigSetting().nullsafety.value ? '!' : '';
int count = 0;
String? result;
while (temp is List) {
Expand Down
Loading

0 comments on commit d2dd34d

Please sign in to comment.