writeClassEncode method

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

Writes a single class encode method to indent.

Implementation

@override
void writeClassEncode(
  KotlinOptions generatorOptions,
  Root root,
  Indent indent,
  Class classDefinition, {
  required String dartPackageName,
}) {
  indent.write('fun toList(): List<Any?> ');
  indent.addScoped('{', '}', () {
    indent.write('return listOf<Any?>');
    indent.addScoped('(', ')', () {
      for (final NamedType field
          in getFieldsInSerializationOrder(classDefinition)) {
        String toWriteValue = '';
        final String fieldName = field.name;
        final String safeCall = field.type.isNullable ? '?' : '';
        if (field.type.isEnum) {
          toWriteValue = '$fieldName$safeCall.raw';
        } else {
          toWriteValue = fieldName;
        }
        indent.writeln('$toWriteValue,');
      }
    });
  });
}