您好,我正在尝试从其他集团收听集团的状态。我正在使用这个包https://pub.dev/packages/bloc
从我的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返回总是假的。
有什么方法可以从其他 Bloc 类中收听 blocState 吗?