writeClassEncode method
void
writeClassEncode(
- KotlinOptions generatorOptions,
- Root root,
- Indent indent,
- Class classDefinition, {
- 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,');
}
});
});
}