Bad state: You cannot close the subject while items are being added from addStream in flutter

后端 未结 2 1877
栀梦
栀梦 2021-01-05 00:41

I am using RxDart to observe changes and update the UI accordingly. When the app launches I am making a network call and successfully getting the data, observe the changes a

相关标签:
2条回答
  • 2021-01-05 01:31

    You can also resolve it be replacing:

    MovieDetailBloc() {
      _movieId.stream.transform(_itemTransformer()).pipe(_trailers);
    }
    

    with

    MovieDetailBloc() {
      _movieId.stream.transform(_itemTransformer()).listen((data) {
        if (!_categories.isClosed) {
          _trailers.add(data);
        }
      });
    }
    
    0 讨论(0)
  • 2021-01-05 01:39

    I think draining the stream should fix the problem

      dispose() async {
        _movieId.close();
        await _trailers.drain();
        _trailers.close();
      }
    

    https://api.dartlang.org/stable/2.0.0/dart-async/Stream-class.html

    0 讨论(0)
提交回复
热议问题