title: stream subscription throwing an error in dart in flutter app?
body: <p>I am using the <code>connectivity</code> plugin in my flutter to check for the connection status, but occasionally hitting the error <code>PlatForm Exception(No active stream to cancel, null)</code> even though i have handled the null case. I have subscribed to the stream in <code>initState</code> and cancelled the subscription in <code>dispose</code> state</p>
  
  <p>my code looks something like this.</p>
  
  <pre><code>    StreamSubscription streamConnectionStatus;
      ------------
      //remaining code
      ------------
      @override
      void initState() {
      getConnectionStatus();
    }
  
  getConnectionStatus() async {
      streamConnectionStatus = new Connectivity()
          .onConnectivityChanged
          .listen((ConnectivityResult result) {
        // Got a new connectivity status!
  
        if (result == ConnectivityResult.mobile ||
            result == ConnectivityResult.wifi) {
          setState(() {
            boolHasConnection = true;
          });
        } else {
          setState(() {
            boolHasConnection = false;
          });
        }
      });
  
  @override
    void dispose() {
      try {
        streamConnectionStatus?.cancel();
      } catch (exception, stackTrace) {
        print(exception.toString());
        updateError(exception.toString(), stackTrace);
      } finally {
        super.dispose();
      }
    }
  </code></pre>
  
  <p>this is actually driving me crazy but i am guessing i am missing something or do i have to change the code.</p>
  
  <p>Many thanks,
  Mahi</p>