Skip to main content

avoid-incomplete-copy-with

added in: 1.1.0
Pro+
preset: recommended

Checks if all parameters from the default constructor are added to the copyWith method.

This rule might be especially useful if you write copyWith manually since it's relatively easy to forget to update the method when the constructor changes.

Example

❌ Bad:

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

final String name;
final String surname;

// LINT: Missing constructor parameters: surname. Try adding missing parameters.
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,
);
}
}