ProductListBloc constructor
ProductListBloc({
- FilterProductModels? filter,
- bool? paged,
- String? orderBy,
- bool? descending,
- bool? detailed,
- EliudQuery? eliudQuery,
- required ProductRepository productRepository,
- int productLimit = 5,
Implementation
ProductListBloc(
{this.filter,
this.paged,
this.orderBy,
this.descending,
this.detailed,
this.eliudQuery,
required ProductRepository productRepository,
this.productLimit = 5})
: _productRepository = productRepository,
super(ProductListLoading()) {
on<LoadProductList>((event, emit) {
if ((detailed == null) || (!detailed!)) {
_mapLoadProductListToState();
} else {
_mapLoadProductListWithDetailsToState();
}
});
on<NewPage>((event, emit) {
pages = pages +
1; // it doesn't matter so much if we increase pages beyond the end
_mapLoadProductListWithDetailsToState();
});
on<ProductChangeQuery>((event, emit) {
eliudQuery = event.newQuery;
if ((detailed == null) || (!detailed!)) {
_mapLoadProductListToState();
} else {
_mapLoadProductListWithDetailsToState();
}
});
on<AddProductList>((event, emit) async {
await _mapAddProductListToState(event);
});
on<UpdateProductList>((event, emit) async {
await _mapUpdateProductListToState(event);
});
on<DeleteProductList>((event, emit) async {
await _mapDeleteProductListToState(event);
});
on<ProductListUpdated>((event, emit) {
emit(_mapProductListUpdatedToState(event));
});
}