diff --git a/Flutter/json_to_dart/CHANGELOG.md b/Flutter/json_to_dart/CHANGELOG.md index e050d22..09482d9 100644 --- a/Flutter/json_to_dart/CHANGELOG.md +++ b/Flutter/json_to_dart/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.4.2 + +* fix camelName error ## 1.4.1 diff --git a/Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart b/Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart index 8985149..5950bec 100644 --- a/Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart +++ b/Flutter/json_to_dart/lib/utils/camel_under_score_converter.dart @@ -44,18 +44,27 @@ String camelName(String name, {bool firstCharLowerCase = true}) { if (name.isNullOrEmpty) { return ''; } + for (final String symbol in symbolSet) { name = name.replaceAll(symbol, '_'); } final List camels = name.split('_'); - for (final String camel in camels) { - if (result.length == 0 && firstCharLowerCase) { - result.write(camel.toLowerCase()); + if (camels.length == 1) { + if (firstCharLowerCase) { + return name.substring(0, 1).toLowerCase() + name.substring(1); } else { - if (!name.isNullOrEmpty) { - result.write(camel.substring(0, 1).toUpperCase()); - result.write(camel.substring(1).toLowerCase()); + return name.substring(0, 1).toUpperCase() + name.substring(1); + } + } else { + for (final String camel in camels) { + if (result.length == 0 && firstCharLowerCase) { + result.write(camel.toLowerCase()); + } else { + if (!name.isNullOrEmpty) { + result.write(camel.substring(0, 1).toUpperCase()); + result.write(camel.substring(1).toLowerCase()); + } } } } diff --git a/Flutter/json_to_dart/pubspec.yaml b/Flutter/json_to_dart/pubspec.yaml index 917d8ba..aa0ba5d 100644 --- a/Flutter/json_to_dart/pubspec.yaml +++ b/Flutter/json_to_dart/pubspec.yaml @@ -11,7 +11,7 @@ description: The tool to convert json to dart code. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.4.1 +version: 1.4.2 environment: sdk: '>=2.17.0 <3.0.0'