I'm quite new to Flutter and Dart, and I have some troubles understanding how to rewrite a class extending an updated version of Equatable.
This works with Equatable 0.4.0:
abstract class Failure extends Equatable {
Failure([List properties = const<dynamic>[]]) : super(properties);
}
However, updating to Equatable 1.0.2 throws an error at super(properties)
:
Too many positional arguments: 0 expected, but 1 found.
Try removing the extra arguments.
I don't understand how to pass over properties
to the super constructor with Equatable 1.0.2
The official Equatable docs describe how to expose your comparison properties to the super class. You actually don't need to call super in your constructor at all. Instead, you are going to use code like the following (not my code, taken from the docs):
class Person extends Equatable {
final String name;
Person(this.name);
@override
List<Object> get props => [name];
}
The key here is to override the props getter. The equatable super class looks to the properties in the props
getter to do its magic.
All equatable does is override the ==
operator in your classes. There is an excellent medium article that goes over some common operator overrides that you may find useful.