Skip to content

Commit 2c1b1ed

Browse files
committed
## 1.4.2
* fix camelName error
1 parent 80de531 commit 2c1b1ed

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Flutter/json_to_dart/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.4.2
2+
3+
* fix camelName error
14

25
## 1.4.1
36

Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,27 @@ String camelName(String name, {bool firstCharLowerCase = true}) {
4444
if (name.isNullOrEmpty) {
4545
return '';
4646
}
47+
4748
for (final String symbol in symbolSet) {
4849
name = name.replaceAll(symbol, '_');
4950
}
5051

5152
final List<String> camels = name.split('_');
52-
for (final String camel in camels) {
53-
if (result.length == 0 && firstCharLowerCase) {
54-
result.write(camel.toLowerCase());
53+
if (camels.length == 1) {
54+
if (firstCharLowerCase) {
55+
return name.substring(0, 1).toLowerCase() + name.substring(1);
5556
} else {
56-
if (!name.isNullOrEmpty) {
57-
result.write(camel.substring(0, 1).toUpperCase());
58-
result.write(camel.substring(1).toLowerCase());
57+
return name.substring(0, 1).toUpperCase() + name.substring(1);
58+
}
59+
} else {
60+
for (final String camel in camels) {
61+
if (result.length == 0 && firstCharLowerCase) {
62+
result.write(camel.toLowerCase());
63+
} else {
64+
if (!name.isNullOrEmpty) {
65+
result.write(camel.substring(0, 1).toUpperCase());
66+
result.write(camel.substring(1).toLowerCase());
67+
}
5968
}
6069
}
6170
}

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.4.1
14+
version: 1.4.2
1515

1616
environment:
1717
sdk: '>=2.17.0 <3.0.0'

0 commit comments

Comments
 (0)