ProductListBloc constructor

ProductListBloc({
  1. FilterProductModels? filter,
  2. bool? paged,
  3. String? orderBy,
  4. bool? descending,
  5. bool? detailed,
  6. EliudQuery? eliudQuery,
  7. required ProductRepository productRepository,
  8. 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));
  });
}