-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathequality_example.dart
More file actions
44 lines (32 loc) · 991 Bytes
/
equality_example.dart
File metadata and controls
44 lines (32 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'package:collection/collection.dart';
import 'package:mek_data_class/mek_data_class.dart';
part 'equality_example.g.dart';
@CustomDataClass()
class Order with _$Order {
final Product product;
final Product? freeProduct;
const Order({required this.product, required this.freeProduct});
}
@CustomDataClass()
class Category with _$Category {
final List<Product> products;
final List<Product?> freeProducts;
const Category({required this.products, required this.freeProducts});
}
@CustomDataClass()
class Product with _$Product {
final int id;
const Product({required this.id});
}
class ProductEquality implements Equality<Product> {
const ProductEquality();
@override
bool equals(Product e1, Product e2) => e1.id == e2.id;
@override
int hash(Product e) => e.id.hashCode;
@override
bool isValidKey(Object? o) => o is Product;
}
class CustomDataClass extends DataClass {
const CustomDataClass() : super(equalities: const [ProductEquality()]);
}