title: How restart stream in flutter Streambuilder?
body: <p>I have a simple stream that returns a countdown when an operation is performed.</p>
  <pre><code>static Stream&lt;double&gt; counterStream = (() async* {
  double i = 0.1;
  double z = 0.0;
  while (z &lt; 0.99) {
    await Future.delayed(Duration(seconds: 1));
    yield  z = z+i;
  }
  })();
  </code></pre>
  <p>I do not start it immediately when the widget is initialized, but by taping on the button that is inside StreamBuilder</p>
  <pre><code> onPressed: () {
           setState(() {
           _result = DatabaseAccess.counterStream;
   });},
  </code></pre>
  <p>First time Stream run correctly, but the second time does not start, and if I close the screen and return to it again, start the stream - I get an error</p>
  <blockquote>
  <p>Bad state: Stream has already been listened to.</p>
  </blockquote>
  <p>I don’t know how to reload a stream that has already completed its execution and, in theory, has the status <code>ConnectionState.done</code> by clicking on the button.</p>
  <p>Full class code</p>
  <pre><code>  class UpdatePage extends StatefulWidget {
    UpdatePage({Key key, this.title}) : super(key: key);
  
    static const String routeName = &quot;/UpdatePage&quot;;
    final String title;
  
    @override
     _UpdatePageState createState() =&gt; new _UpdatePageState();
   }
  
  
   class _UpdatePageState extends State&lt;UpdatePage&gt; {
  
   Stream&lt;double&gt; _result;
  
  @override
  Widget build(BuildContext context) {
  
  
  return new Scaffold(
      appBar: new AppBar(
        title: new Text(&quot;&quot;),
      ),
      body: SafeArea(
          child: StreamBuilder&lt;double&gt;(
            stream:  _result,
            builder: (BuildContext context, AsyncSnapshot&lt;double&gt; snapshot) {
              List&lt;Widget&gt; children;
              if (snapshot.hasError) {
                children = &lt;Widget&gt;[
                  Center(
                    child: Icon(
                      Icons.error_outline,
                      color: Colors.red,
                      size: 60,
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 16),
                    child: Text('Error: ${snapshot.error}'),
                  )
                ];
              } else {
                switch (snapshot.connectionState) {
                  case ConnectionState.none:
                    children = &lt;Widget&gt;[
                      Center(child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Container(child: Text(&quot;Обновление данных&quot;, style: new TextStyle( fontSize: 18.0))),
                      )),
                      Center(
                        child: Container(padding: EdgeInsets.all(20.0),child: RaisedButton.icon(
                          textColor: Colors.white,
                          icon:   FaIcon(FontAwesomeIcons.retweet, size: 18,),
                          color: Color(0xFF6200EE), label: Text(&quot;Обновить&quot;),
                          onPressed: () {
                            setState(() {
                              _result = DatabaseAccess.counterStream;
                            });
                          },
                        ),),
                      ),
                    ];
                    break;
                  case ConnectionState.waiting:
                    children = &lt;Widget&gt;[
                      Center(
                        child: new Padding(
                          padding: EdgeInsets.symmetric(horizontal: 10.0),
                        ),
                      ),
                      new CircularPercentIndicator(
                        radius: MediaQuery.of(context).size.width/2,
                        lineWidth: 4.0,
                        center: new Text('', style: new TextStyle( fontSize: 20.0)),
                      ),
                    ];
                    break;
                  case ConnectionState.active:
                    children = &lt;Widget&gt;[
                      Center(
                        child: new Padding(
                          padding: EdgeInsets.symmetric(horizontal: 10.0),
                        ),
                      ),
                      new CircularPercentIndicator(
                        radius: MediaQuery.of(context).size.width/2,
                        lineWidth: 4.0,
                        percent: snapshot.data,
                        center: new Text('${snapshot.data.toStringAsFixed(2)}', style: new TextStyle( fontSize: 20.0)),
                        progressColor: Colors.orange,
  
                      ),
  
                    ];
                    break;
                  case ConnectionState.done:
                    children = &lt;Widget&gt;[
                      new CircularPercentIndicator(
                        radius: MediaQuery.of(context).size.width/2,
                        lineWidth: 4.0,
                        center: new Icon(
                          Icons.done,
                          size: MediaQuery.of(context).size.width/4,
                          color: Colors.green,
                        ),
                        backgroundColor: Colors.grey,
                        progressColor: Colors.orange,
                      )
                      ,
                      Center(child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Container(child: Text(&quot;Обновление успешно завершено&quot;, style: new TextStyle( fontSize: 18.0))),
                      )),
                      Center(
                        child: Container(padding: EdgeInsets.all(20.0),child: RaisedButton.icon(
                          textColor: Colors.white,
                          icon:   FaIcon(FontAwesomeIcons.retweet, size: 18,),
                          color: Color(0xFF6200EE), label: Text(&quot;Обновить&quot;),
  
                          onPressed: () {
                              setState(() {
                              _result = DatabaseAccess.counterStream;
                              });
                          },
  
                        ),),
                      ),
                    ];
  
                    break;
                }
              }
  
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: children,
              );
            },
          )
      ));
  
  ;
  </code></pre>
  <p>}</p>
  <p>}</p>