相关疑难解决方法(0)

Flutter 从其他 Bloc 监听 Bloc 状态

您好,我正在尝试从其他集团中收听集团的状态。我正在使用这个包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();
  }
Run Code Online (Sandbox Code Playgroud)

现在我有这个问题:在调试时我试图打印 stateAuth 它返回:

stateAuth = {AuthenticationAuthenticated} AuthenticationAuthenticated
   props = {_ImmutableList} size = 0
Run Code Online (Sandbox Code Playgroud)

但是stateAuth 是 AuthenticationAuthenticated返回始终为 false。

有没有办法从其他 Bloc …

flutter flutter-bloc

9
推荐指数
4
解决办法
1万
查看次数

标签 统计

flutter ×1

flutter-bloc ×1