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);
}
Author by
Mohammed Nabil
Updated on December 31, 2022Comments
-
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 insideinitState
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 over 2 yearsadd
super.initState();
below of the void initState() { -
Mohammed Nabil over 2 years@RavindraS.Patil that doesn't work still only one event is calling.
-
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 callsuper.initState()
-
-
Mohammed Nabil over 2 yearsBostanci But in this there are two events
LoadRestaurantCuisineDishes
andLoadRestaurantRecommendedForYouEvent
-
Emir Bostancı over 2 yearsWhat 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.