2021年3月25日星期四

Bloc Listener : access to the previous state

There is one line of my code in my BlocListener that I would like to run only if a condition on the previous state is met. So is it possible to get access to the previous state in the listener, I know I can get access to it in the listenWhen parameter.

BlocListener<AuthenticationBloc, AuthenticationState>(              listener: (context, state) {                switch (state.status) {                  case AuthenticationStatus.authenticated:                      context.read<GetOffersCubit>().getOffersInMyArea();                    context.read<GetRequestsCubit>().getRequestsInMyArea();                    context.read<GetFavoritesCubit>().getFavorites();                    PushNotificationsManager instanceNotificationManager = PushNotificationsManager();                    instanceNotificationManager.init(state.user.id);                      // this line should run only if previous.status != AuthenticationStatus.authenticated                    context.read<NavigatorBloc>().add(GoToMainFrameScreen());  
https://stackoverflow.com/questions/66805739/bloc-listener-access-to-the-previous-state March 26, 2021 at 02:39AM

没有评论:

发表评论