title: Flutter: Stream has already been listened to
body: <p>I'm using BLoC to load my Preset Objects from Firestore. This is my Bloc Model:</p>
  
  <pre><code>class StatisticsBloc extends BlocBase {
  
    List&lt;Preset&gt; _presets;
  
    StreamController&lt;List&lt;Preset&gt;&gt; _presetsController = new StreamController();
  
    Stream&lt;List&lt;Preset&gt;&gt; get getPresets =&gt; _presetsController.stream.asBroadcastStream();
  
    StatisticsBloc() {
      print('init Statistics Bloc');
      _presets = [];
      Firestore.instance.collection('Presets').snapshots().asBroadcastStream().listen(_onPresetsLoaded);
    }
  
    @override
    void dispose() {
      print('Disposed Statistics Bloc');
      _presetsController.close();
    }
  
    void _onPresetsLoaded(QuerySnapshot data) {
      _presets = [];
      data.documents.forEach((DocumentSnapshot snap) {
        Preset preset = Preset.fromDoc(snap);
        _presets.add(preset);
      });
      _presetsController.sink.add(_presets);
    }
  }
  </code></pre>
  
  <p>Then I display the List like this:</p>
  
  <pre><code>class StatisticsPage extends StatelessWidget {
  
    StatisticsPage() {
      print('Created StatisticsPage');
    }
  
    @override
    Widget build(BuildContext context) {
      final StatisticsBloc statisticsBloc = BlocProvider.of&lt;StatisticsBloc&gt;(context);
      final List&lt;Preset&gt; _ = [];
  
      print(statisticsBloc.getPresets.isBroadcast);
  
      return Scaffold(
        appBar: AppBar(
          title: Text('Statistics'),
        ),
        body: StreamBuilder(
          stream: statisticsBloc.getPresets,
          initialData: _,
          builder: (BuildContext context, AsyncSnapshot&lt;List&lt;Preset&gt;&gt; snapshot) {
            if (snapshot.hasData) {
              return ListView(
                children: snapshot.data.map((Preset preset) {
                  print(preset.name);
                  return new ListTile(
                    title: new Text(preset.name),
                    subtitle: new Text(preset.id),
                  );
                }).toList(),
              );
            } else {
              Text('No Data');
              print('No Data');
            }
          }
        )
      );
    }
  }
  </code></pre>
  
  <p>The problem is, I show the the <code>StatisticsPage</code> in a Tabbar, so it will be build muliple times when I switch tabs and go back to it. On the first visit it works but when I switch tabs and go back to it, the widget get rebuild and I get the error: <code>Bad state: Stream has already been listened to.</code>. I tried to declare the <code>getPresets</code> Stream as a BroadcastStream as you can see in <code>StatisitcsBloc</code> but that doesn't work.</p>
  
  <p>Also as a secoundary question: Is there a better way to transform <code>Stream&lt;QuerySnapshot&gt;</code> that I get from Firestore to <code>Stream&lt;List&lt;Presets&gt;&gt;</code>? </p>