Call two event at the same time in initState

212

You can use transformEvents method of bloc with rxDart like mentioned in issue here

First, you should import rxDart and then add transformEvents function to your bloc like:

@override
  Stream<Transition< BookEvent, BooksState >> transformEvents(
    Stream< BookEvent > events,
    TransitionFunction< BookEvent, BooksState > transitionFn,
  ) {
    return events.flatMap(transitionFn);
  }
Share:
212
Mohammed Nabil
Author by

Mohammed Nabil

Updated on December 31, 2022

Comments

  • Mohammed Nabil
    Mohammed Nabil over 1 year

    How to call two different events at the same time inside initState because these two events calling different api's. Whenever i put two events inside initState only one event is triggers. I seen some articles that it is not possible to call rather than creating two different bloc's. Any possibilities to calling two events at the same time.

      late HomeBloc homeBloc;
      @override
      void initState() {
        homeBloc = BlocProvider.of<HomeBloc>(context);
        homeBloc.add(LoadRestaurantCuisineDishes());
        homeBloc.add(LoadRestaurantRecommendedForYouEvent());
        super.initState();
      }
    
    • Ravindra S. Patil
      Ravindra S. Patil over 2 years
      add super.initState(); below of the void initState() {
    • Mohammed Nabil
      Mohammed Nabil over 2 years
      @RavindraS.Patil that doesn't work still only one event is calling.
    • Nagual
      Nagual over 2 years
      add super.initState(); below of the void initState() useless tip, if you open initState implementation you will se it's empty, so no matter when to call super.initState()
  • Mohammed Nabil
    Mohammed Nabil over 2 years
    Bostanci But in this there are two events LoadRestaurantCuisineDishes and LoadRestaurantRecommendedForYouEvent
  • Emir Bostancı
    Emir Bostancı over 2 years
    What this solution offer is: Non blocking event flow. So when you do this, one event is not blocking other one, but processed in order you call.