props
getter instead of super
class Person extends Equatable { final String name; Person(this.name) : super([name]); }
class Person extends Equatable { final String name; Person(this.name); @override List<Object> get props => [name]; }
Based on feedback/observations, one of the most common mistakes made when using Equatable is forgetting to pass the props to super. This change will force developers to override props
making it a lot less error-prone.
@immutable
decorator is redundant and can be omitted.@immutable class Person extends Equatable { ... }
class Person extends Equatable { ... }
Equatable enforces immutable internally so the decorator is not necessary.
class MyClass extends Equatable { MyClass([List<Object> props = const[]]) : super(props); } class MySubClass extends MyClass { final int data; MySubClass(this.data) : super([data]); }
class MyClass extends Equatable { const MyClass(); } class MySubClass extends MyClass { final int data; const MySubClass(this.data); @override List<Object> get props => [data]; }
Since props are no longer passed via super
having optional props in the abstract constructor is unnecessary. In addition, the props
getter allows for const
classes which offer significant performance improvements. const
constructors should be used over non-const constructors.