generate method

  1. @override
String generate(
  1. List<ClassMember> members
)

Implementation

@override
String generate(List<ClassMember> members) {
  var constructor = '';
  for (var member in members) {
    if (!(member is FieldDeclaration)) continue;
    final name = member.fields.variables.first.name.lexeme;
    final isNullable = member.fields.type.toString().contains('?');
    if (isNullable) {
      constructor += 'this.$name,\n';
    } else {
      constructor += 'required this.$name,\n';
    }
  }
  return '''
    $className();

    $className.build({
      $constructor
    });

  ''';
}