Sorting..
This commit is contained in:
parent
ecc68040f1
commit
87193bf168
|
|
@ -71,6 +71,23 @@ abstract class ProductEntity implements Built<ProductEntity, ProductEntityBuilde
|
||||||
//@JsonKey(name: 'custom_value2')
|
//@JsonKey(name: 'custom_value2')
|
||||||
//String customValue2;
|
//String customValue2;
|
||||||
|
|
||||||
|
int compareTo(ProductEntity product, String sortField, bool sortAscending) {
|
||||||
|
int response = 0;
|
||||||
|
ProductEntity productA = sortAscending ? this : product;
|
||||||
|
ProductEntity productB = sortAscending ? product: this;
|
||||||
|
|
||||||
|
switch (sortField) {
|
||||||
|
case ProductFields.cost:
|
||||||
|
response = productA.cost.compareTo(productB.cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response == 0) {
|
||||||
|
return productA.productKey.compareTo(productB.productKey);
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProductEntity._();
|
ProductEntity._();
|
||||||
factory ProductEntity([updates(ProductEntityBuilder b)]) = _$ProductEntity;
|
factory ProductEntity([updates(ProductEntityBuilder b)]) = _$ProductEntity;
|
||||||
static Serializer<ProductEntity> get serializer => _$productEntitySerializer;
|
static Serializer<ProductEntity> get serializer => _$productEntitySerializer;
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,7 @@ List<ProductEntity> filteredProductsSelector(
|
||||||
list.sort((productAId, productBId) {
|
list.sort((productAId, productBId) {
|
||||||
var productA = productState.map[productAId];
|
var productA = productState.map[productAId];
|
||||||
var productB = productState.map[productBId];
|
var productB = productState.map[productBId];
|
||||||
var sortField = productUIState.sortField;
|
return productA.compareTo(productB, productUIState.sortField, productUIState.sortAscending);
|
||||||
|
|
||||||
switch (sortField) {
|
|
||||||
case ProductFields.productKey:
|
|
||||||
return productA.productKey.compareTo(productB.productKey);
|
|
||||||
case ProductFields.cost:
|
|
||||||
return productA.cost.compareTo(productB.cost);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
print('== SORTING LIST');
|
print('== SORTING LIST');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue