prefer_equatable_mixin
v0.4.0 Warning Fix Type Annotations
Flags classes that directly extend Equatable instead of using EquatableMixin. Extending Equatable consumes the single extends slot in Dart, preventing your class from inheriting from any other base class. Using the mixin keeps the extends slot free while providing identical functionality.
Why use this rule
Section titled “Why use this rule”Dart only allows single inheritance. By using with EquatableMixin instead of extends Equatable, you preserve the ability to extend another meaningful base class while still getting value equality. This is especially important for domain models that might need to extend an existing hierarchy.
See also: equatable package
import 'package:equatable/equatable.dart';
class BadPerson extends Equatable { const BadPerson(this.name, this.age); final String name; final int age;
@override List<Object?> get props => [name, age];}
abstract class BadBaseEntity extends Equatable { const BadBaseEntity();}import 'package:equatable/equatable.dart';
class GoodPerson with EquatableMixin { GoodPerson(this.name, this.age); final String name; final int age;
@override List<Object?> get props => [name, age];}
// Can extend another class while using EquatableMixinclass Pet extends Animal with EquatableMixin { const Pet(super.species, this.name); final String name;
@override List<Object?> get props => [species, name];}
abstract class GoodBaseEntity with EquatableMixin { const GoodBaseEntity();}Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_equatable_mixin: false