Flutter nested StreamBuilders causing Bad state: Stream has already been listened to

后端 未结 2 1291
陌清茗
陌清茗 2021-02-19 23:34

I\'m trying to build a Flutter app using the BLoC pattern described in the video Flutter / AngularDart – Code sharing, better together (DartConf 2018)

A BLoC is basicall

2条回答
  •  猫巷女王i
    2021-02-20 00:08

    As i understand BLoC you should only have one output stream which is connected to a StreamBuilder. This output stream emits a model which contains all required state.

    You can see how its done here: https://github.com/ReactiveX/rxdart/blob/master/example/flutter/github_search/lib/github_search_widget.dart

    New Link: https://github.com/ReactiveX/rxdart/blob/master/example/flutter/github_search/lib/search_widget.dart

    If you need to combine multiple steams to generate you model (sowLoading and submitEnabled), you can use Observable.combineLatest from RxDart to merge multiple streams into one stream. I use this approach and it works really nice.

提交回复
热议问题