你好,我正在尝试从另一个区块监听区块的状态。
我正在使用这个包 https://pub.dev/packages/bloc。
从我的 UserBloc 中,我想要监听 AuthBloc,并且当它处于 AuthenticationAuthenticated 状态时,UserBloc 应该触发一个事件。
目前我有一个问题: 在调试时,当我尝试打印stateAuth时,它返回:
但是stateAuth是AuthenticationAuthenticated,总是返回false。
有没有办法从其他Bloc类中监听blocState?
从我的 UserBloc 中,我想要监听 AuthBloc,并且当它处于 AuthenticationAuthenticated 状态时,UserBloc 应该触发一个事件。
final UserRepository userRepository;
final authBloc;
StreamSubscription authSub;
UserBloc({ @required this.userRepository, @required this.authBloc}) {
authSub = authBloc.listen((stateAuth) {
//here is my problem because stateAuth, even is AuthenticationAuthenticated it return always false.
if (stateAuth is AuthenticationAuthenticated) {
this.add(GetUser()) ;
}
});
}
@override
Future<void> close() async {
authSub?.cancel();
super.close();
}
目前我有一个问题: 在调试时,当我尝试打印stateAuth时,它返回:
stateAuth = {AuthenticationAuthenticated} AuthenticationAuthenticated
props = {_ImmutableList} size = 0
但是stateAuth是AuthenticationAuthenticated,总是返回false。
有没有办法从其他Bloc类中监听blocState?