Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bloc 7.2 migration – passing parameters inside streams

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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, ...}

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading