GetterPropsBuilder function

Method GetterPropsBuilder({
  1. required String className,
  2. required List<FieldInfo> fields,
})

Implementation

Method GetterPropsBuilder({
  required String className,
  required List<FieldInfo> fields,
}) {
  return Method((builder) {
    builder.docs.addAll([
      '/// The list of properties that constitute the state of this [$className].',
      '///',
      '/// This property is used by the [==] operator and the [hashCode] getter to',
      '/// compare two [$className] instances for equality.',
    ]);
    builder.annotations.add(refer('override'));
    builder.name = 'props';
    builder.type = MethodType.getter;
    builder.returns = refer('List<Object?>');
    builder.body = Code('''
    return [
      ${fields.map((field) => field.name).join(', ')},
    ];
  ''');
  });
}