Flutter : Bad state: Stream has already been listened to

前端 未结 11 1326
灰色年华
灰色年华 2020-12-03 04:21

    class MyPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Defaul         


        
11条回答
  •  無奈伤痛
    2020-12-03 04:44

    You could use broadcast, which allows to listen stream more than once, but it also prevents from listening past events:

    Broadcast streams do not buffer events when there is no listener.

    A better option is to use BehaviorSubject from rxdart package class as StreamController. BehaviorSubject is:

    A special StreamController that captures the latest item that has been added to the controller, and emits that as the first item to any new listener.

    The usage is as simple as:

    StreamController<...> _controller = BehaviorSubject();
    

提交回复
热议问题