【发布时间】:2021-06-22 14:54:37
【问题描述】:
在我的BlocListener 中有一行代码,我只想在满足前一个状态的条件时运行。那么是否可以在listener 中访问之前的状态,我知道我可以在listenWhen 参数中访问它。
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());
【问题讨论】: