Skip to main content

avoid-incomplete-copy-with

added in: 1.1.0

Checks if all the parameters from the default constructor are included in the copyWith method.

Example

❌ Bad:

class Person {
const Person({
required this.name,
required this.surname,
});

final String name;
final String surname;

// LINT
Person copyWith({String? name}) {
return Person(
name: name ?? this.name,
surname: surname,
);
}
}

✅ Good:

class Person {
const Person({
required this.name,
required this.surname,
});

final String name;
final String surname;

Person copyWith({String? name, String? surname}) {
return Person(
name: name ?? this.name,
surname: surname ?? this.surname,
);
}
}