generateAbstractClass function

String generateAbstractClass (ClassElement element)

Implementation

String generateAbstractClass(ClassElement element) {
  final generatedClass = ClassBuilder()
    ..abstract = true
    ..name = "${element.name}Preferences"
    ..methods.addAll(element.fields.map((field) => Method((b) => b
      ..name = "${field.name}Async"
      ..returns = refer("Future<${field.type.displayName}>"))))
    ..methods.addAll(element.fields.map((field) => Method((b) => b
      ..name = "${field.name}AsyncSet"
      ..requiredParameters.add(Parameter((b) => b
        ..name = 'value'
        ..type = refer(field.type.displayName)))
      ..returns = refer("Future<void>"))));
  final emitter = DartEmitter();
  return (DartFormatter().format('${generatedClass.build().accept(emitter)}'));
}