Home > OS >  Bloc 7.2 migration - passing parameters inside streams
Bloc 7.2 migration - passing parameters inside streams

Time:01-18

I'm currently migrating a project from Bloc 7.0 to bloc 7.2

I use to have a stream which I would yield* inside different Streams & passing every time a different value as parameter

 Stream<CartState> _mapCheckCart({CART_STATUS status}) async*
{...}

but with BloC 7.2 I had to rewrite my stream as follow and don't know - now - how to pass in a parameter :

 Future<void> _onCheckCart(event, Emitter<CartState> emit) async {
    ...
      emit(state.checkCartSuccess(
        amounts: cart.amounts,
        status: status, // I need to pass in the status here 
      ));
     ...
  }

Ideally I'd like to use _onCheckCart like this

    on<CheckCart>(
        _onCheckCart(statusOnSuccess: CART_STATUS.CHECK_CART_SUCCESS));

    on<CheckCustomerInformation>(_onCheckCart(
        statusOnSuccess: CART_STATUS.CHECK_CUSTOMER_INFORMATION_SUCCESS));

CART_STATUS is an enum

enum CART_STATUS {LOADING,READY,CHECK_CART_IN_PROGRESS, ...}

CodePudding user response:

Definition:

Future<void> _onCheckCart(event, Emitter<CartState> emit, CART_STATUS status) async {

Call (or rather: registration of call):

on<CheckCart>((ev, em) =>
    _onCheckCart(ev, em, CART_STATUS.CHECK_CART_SUCCESS));

on<CheckCustomerInformation>((ev, em) =>
    _onCheckCart(ev, em, CART_STATUS.CHECK_CUSTOMER_INFORMATION_SUCCESS));

Your _onCheckCart function has no type for event. You should use the proper type there.

  •  Tags:  
  • Related