【问题标题】:flutter streams bloc to show handle visible state颤动流块以显示句柄可见状态
【发布时间】:2020-03-16 11:40:32
【问题描述】:

我有一个小部件isLive,它根据 bloc 返回的值更改状态。但是每次我运行应用程序时,我都会得到

在 null 上调用了 getter 'progressStateStream'

我试过关注这个answer

 Widget isLive() {
    return Container(
        child: StreamBuilder<bool>(
      stream: _bloc.progressStateStream,
      builder: (context, snapshot) {

        return Visibility(
          maintainState: true,
          visible: snapshot.data ?? false,
          child: ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(10)),
            child: Container(
              color: Colors.pink[50],
              height: 50,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[

                  Text("yaay i'm visible"),

                  RaisedButton(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20)),
                    child: Text(
                      "hide"
                    ),
                    color: Colors.white,
                    onPressed: () {
                      _bloc.changeProgressState(state: false);
                    },
                  )
                ],
              ),
            ),
          ),
        );
      },
    ));
  }

这是我的集团

  //this Subject allows sending data, error and done events to the listener
  final PublishSubject<bool> _progressStateSubject = new PublishSubject();

  //the listener are streaming on changes
  Observable<bool> get progressStateStream => _progressStateSubject.stream;

  //to change your progress state
  void changeProgressState({bool state}) => _progressStateSubject.sink.add(state);

另外,如果我想用 hydrad bloc 保存状态,我会怎么做呢

【问题讨论】:

  • 你的初始化状态在哪里?
  • 我在初始化状态下没有初始化它
  • 该消息意味着_bloc 为空。所以请告诉我你在哪里输入_bloc的实例。
  • 设法通过将我的 bloc 初始化为 init 状态来解决它,谢谢_bloc = RBloc(); _bloc.progressStateStream;
  • 请用新答案更新您的问题解决方案。

标签: flutter flutter-layout bloc


【解决方案1】:

通过将 bloc 添加到 init 状态来将我的 bloc 初始化为 init 状态来修复它

_bloc = RBloc();
 _bloc.progressStateStream;

【讨论】:

    猜你喜欢
    • 2020-08-23
    • 2019-11-28
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 2021-11-30
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多