Skip to content

Commit 793b979

Browse files
committed
Fix copyProperty isEmpty case
1 parent 4e2e1e3 commit 793b979

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

Flutter/json_to_dart/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.5.1
2+
3+
* Fix copyProperty isEmpty case
4+
15
## 1.5.0
26

37
* add copyWith support

Flutter/json_to_dart/lib/models/dart_object.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ class DartObject extends DartProperty {
458458
]));
459459

460460
if (ConfigSetting().addCopyMethod.value) {
461+
if (copyProperty.isEmpty) {
462+
copyProperty = item.name.value;
463+
}
461464
copyWithBodySb
462465
.writeLine('${item.name}: ${item.name}?? $copyProperty,');
463466
copyWithParameterSb.writeLine(

Flutter/json_to_dart/lib/models/dart_property.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class DartProperty extends Equatable {
245245
}
246246

247247
result =
248-
" for (final dynamic item in ${DartHelper.jsonRes}['$key']$nonNullable) { if (item != null) { $addString }}";
248+
" for (final dynamic item in ${DartHelper.jsonRes}['$key']$nonNullable as List<dynamic>) { if (item != null) { $addString }}";
249249
} else {
250250
addString = 'items$count.add($item); ';
251251

Flutter/json_to_dart/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description: The tool to convert json to dart code.
1111
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
1212
# Read more about iOS versioning at
1313
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14-
version: 1.5.0
14+
version: 1.5.1
1515

1616
environment:
1717
sdk: '>=3.5.0 <4.0.0'

0 commit comments

Comments
 (0)