writeDataClass method

  1. @override
void writeDataClass(
  1. DartOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Class classDefinition, {
  5. required String dartPackageName,
})
override

Writes a single data class to indent.

Implementation

@override
void writeDataClass(
  DartOptions generatorOptions,
  Root root,
  Indent indent,
  Class classDefinition, {
  required String dartPackageName,
}) {
  indent.newln();
  addDocumentationComments(
      indent, classDefinition.documentationComments, _docCommentSpec);

  indent.write('class ${classDefinition.name} ');
  indent.addScoped('{', '}', () {
    _writeConstructor(indent, classDefinition);
    indent.newln();
    for (final NamedType field
        in getFieldsInSerializationOrder(classDefinition)) {
      addDocumentationComments(
          indent, field.documentationComments, _docCommentSpec);

      final String datatype = _addGenericTypesNullable(field.type);
      indent.writeln('$datatype ${field.name};');
      indent.newln();
    }
    writeClassEncode(
      generatorOptions,
      root,
      indent,
      classDefinition,
      dartPackageName: dartPackageName,
    );
    indent.newln();
    writeClassDecode(
      generatorOptions,
      root,
      indent,
      classDefinition,
      dartPackageName: dartPackageName,
    );
  });
}