diff --git a/mek_data_class_generator/CHANGELOG.md b/mek_data_class_generator/CHANGELOG.md index 950e816..27fcaf9 100644 --- a/mek_data_class_generator/CHANGELOG.md +++ b/mek_data_class_generator/CHANGELOG.md @@ -1,3 +1,5 @@ +## 1.3.1 +- fix: private fields class generation ## 1.3.0 - fix: unnecessary parentheses on `toString` method [#20](https://github.com/BreX900/data_class/issues/20) diff --git a/mek_data_class_generator/lib/src/creators/fields_class_creator.dart b/mek_data_class_generator/lib/src/creators/fields_class_creator.dart index fe35bca..7bedb93 100644 --- a/mek_data_class_generator/lib/src/creators/fields_class_creator.dart +++ b/mek_data_class_generator/lib/src/creators/fields_class_creator.dart @@ -28,6 +28,8 @@ class FieldsClassCreator extends Creator { yield createLibraryClassFields(); } + String get _classPrefix => config.fieldsClassVisible ? '' : '_'; + String _createFieldPath(FieldSpec fieldSpec, bool hasFieldMap) { return hasFieldMap ? '\$_path\${_get(\'${fieldSpec.name}\')}' : '\${_path}${fieldSpec.name}'; } @@ -42,7 +44,7 @@ class FieldsClassCreator extends Creator { final fieldClassSpec = ClassSpec.from(config, fieldClassElement, fieldClassReader); if (!fieldClassSpec.createFieldsClass) return null; - final keysClassName = '${fieldClassElement.name}Fields'; + final keysClassName = '$_classPrefix${fieldClassElement.name}Fields'; return Method((b) => b ..returns = Reference(keysClassName) @@ -56,7 +58,7 @@ class FieldsClassCreator extends Creator { final jsonSerializable = _jsonSerializableType.firstAnnotationOf(classSpec.element); final hasFieldMap = ConstantReader(jsonSerializable).peek('createFieldMap')?.boolValue ?? false; - final className = '${config.fieldsClassVisible ? '' : '_'}${classSpec.element.name}Fields'; + final className = '$_classPrefix${classSpec.element.name}Fields'; final methodsFields = _paramsSpecs.map((field) { final fieldPath = _createFieldPath(field, hasFieldMap); diff --git a/mek_data_class_generator/pubspec.yaml b/mek_data_class_generator/pubspec.yaml index 6658d52..de9da0e 100644 --- a/mek_data_class_generator/pubspec.yaml +++ b/mek_data_class_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: mek_data_class_generator -version: 1.3.0 +version: 1.3.1 description: > Code generator for data_class to generate `hashCode`, `==`, `toString`, `copyWith` and `change` methods