documentation and example updates
diff --git a/README.md b/README.md
index 3c684c0..793f89b 100644
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@
```yaml
dependencies:
- equatable: ^0.4.0
+ equatable: ^0.5.0
```
Next, we need to install it:
@@ -145,6 +145,21 @@
We can now compare instances of `Person` just like before without the pain of having to write all of that boilerplate.
**Note:** Equatable is designed to only work with immutable objects so all member variables must be final.
+Equatable also supports `const` constructors but you'll need to override `props` instead of passing the props to super.
+
+```dart
+import 'package:equatable/equatable.dart';
+
+class Person extends Equatable {
+ final String name;
+
+ const Person(this.name);
+
+ @override
+ List<Object> get props => [name];
+}
+```
+
## Recap
### Without Equatable
diff --git a/example/main.dart b/example/main.dart
index 2dc0983..6f3975f 100644
--- a/example/main.dart
+++ b/example/main.dart
@@ -7,6 +7,16 @@
Credentials({this.username, this.password}) : super([username, password]);
}
+class ConstCredentials extends Equatable {
+ final String username;
+ final String password;
+
+ ConstCredentials({this.username, this.password});
+
+ @override
+ List<Object> get props => [username, password];
+}
+
class EquatableDateTime extends DateTime with EquatableMixin {
EquatableDateTime(
int year, [
@@ -28,14 +38,25 @@
void main() {
// Extending Equatable
final credentialsA = Credentials(username: 'Joe', password: 'password123');
+ final constCredentialsA =
+ ConstCredentials(username: 'Joe', password: 'password123');
final credentialsB = Credentials(username: 'Bob', password: 'password!');
+ final constCredentialsB =
+ ConstCredentials(username: 'Bob', password: 'password!');
final credentialsC = Credentials(username: 'Bob', password: 'password!');
+ final constCredentialsC =
+ ConstCredentials(username: 'Bob', password: 'password!');
print(credentialsA == credentialsA); // true
+ print(constCredentialsA == constCredentialsA); // true
print(credentialsB == credentialsB); // true
+ print(constCredentialsB == constCredentialsB); // true
print(credentialsC == credentialsC); // true
+ print(constCredentialsC == constCredentialsC); // true
print(credentialsA == credentialsB); // false
+ print(constCredentialsA == constCredentialsB); // false
print(credentialsB == credentialsC); // true
+ print(constCredentialsB == constCredentialsC); // true
// Equatable Mixin
final dateTimeA = EquatableDateTime(2019);