writeDataClass method
void
writeDataClass(
- DartOptions generatorOptions,
- Root root,
- Indent indent,
- Class klass, {
- required String dartPackageName,
override
Writes a single data class to indent
.
Implementation
@override
void writeDataClass(
DartOptions generatorOptions,
Root root,
Indent indent,
Class klass, {
required String dartPackageName,
}) {
final Set<String> customClassNames =
root.classes.map((Class x) => x.name).toSet();
final Set<String> customEnumNames =
root.enums.map((Enum x) => x.name).toSet();
indent.newln();
addDocumentationComments(
indent, klass.documentationComments, _docCommentSpec);
indent.write('class ${klass.name} ');
indent.addScoped('{', '}', () {
_writeConstructor(indent, klass);
indent.newln();
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
addDocumentationComments(
indent, field.documentationComments, _docCommentSpec);
final String datatype = _addGenericTypesNullable(field.type);
indent.writeln('$datatype ${field.name};');
indent.newln();
}
writeClassEncode(
generatorOptions,
root,
indent,
klass,
customClassNames,
customEnumNames,
dartPackageName: dartPackageName,
);
indent.newln();
writeClassDecode(
generatorOptions,
root,
indent,
klass,
customClassNames,
customEnumNames,
dartPackageName: dartPackageName,
);
});
}