Flutter bloc new version deprecated mapEventToState

352

it should be something like that in your bloc class

class ProductsBloc extends Bloc<ProductsEvent, ProductsState> {
  final GetMoreProducts moreProductsUsecase;
  final GetProducts getProductsUsecase;

  ProductsBloc({
    required this.moreProductsUsecase,
    required this.getProductsUsecase,
  }) : super(ProductsInitial()) {

    on<GetProductsEvent>(_onGetProducts);

  }

and the function call can be like this

_onGetProducts(GetProductsEvent event, Emitter<ProductsState> emit) async {
    emit(LoadingProductsState());
    var result = await getProductsUsecase();
    result.fold(
        (l) => emit(LoadFailedState()),
        (r) => { emit(ProductsLoadedState(products: products, isReachedMax: false)),
            });
  }
Share:
352
Admin
Author by

Admin

Updated on January 04, 2023

Comments

  • Admin
    Admin over 1 year

    I have bloc hierarchy,in child bloc's mapEvenToState I used super.mapEventToState.In bloc new version where mapEventToState is deprecated, what should I use instead of super.mapEventToState?In know about on<Event>,but what is equivalent for super.mapEventToState?