CartBloc constructor

CartBloc(
  1. String appId,
  2. AccessBloc accessBloc
)

Implementation

CartBloc(
  this.appId,
  this.accessBloc,
) : super(CartUninitialised()) {
  var accessState = accessBloc.state;
  on<LoadCart>((event, emit) async {
    if (accessState is LoggedIn) {
      emit(await toEmit(accessState));
    }
  });

  on<AddProduct>((event, emit) async {
    if (accessState is LoggedIn) {
      await _updateCartChangeAmount(accessState, event.product, event.amount);
      var action = event.continueShoppingAction!;
      if (action is GotoPage) {
        accessBloc.add(GotoPageEvent(
          action.app,
          action.pageID,
        ));
      } else {
        print('The continueShoppingAction is not a GotoPage action');
      }
      emit(await toEmit(accessState));
    }
  });

  on<SimpleAddProduct>((event, emit) async {
    if (accessState is LoggedIn) {
      await _updateCartChangeAmount(accessState, event.product, event.amount);
      emit(await toEmit(accessState));
    }
  });

  on<RemoveProduct>((event, emit) async {
    if (accessState is LoggedIn) {
      await _updateCartChangeAmount(
          accessState, event.product, -event.amount);
      emit(await toEmit(accessState));
    }
  });

  on<EmptyCart>((event, emit) async {
    if (accessState is LoggedIn) {
      await _emptyCart(accessState);
      emit(await toEmit(accessState));
    }
  });
}