title: How do I cancel a subscription for StreamBuilder in flutter?
body: <p>I m currently facing a problem which is that my entire <code>HomeScreen</code> page is dependant on the <code>StreamBuilder</code> and the data that it is receiving from the firestore.</p>
  <p>Everything is working well, but when I click sign out, I got this error :</p>
  <blockquote>
  <p>The caller does not have permission to execute the specified
  operation.</p>
  </blockquote>
  <p>This is my firestore security rules :</p>
  <pre><code>rules_version = '2';
  
  service cloud.firestore {
  
  match /databases/{database}/documents {
  
   match /{document=**} {
  
    allow read, write: if request.auth != null;
  
    }
  
   }
  
  }
  </code></pre>
  <p>I did some research and found that the reason was probably I did not Un-Subscribe to the stream when I press log out. Here is my stream Builder code :</p>
  <pre><code>late Stream&lt;QuerySnapshot&lt;Map&lt;String, dynamic&gt;&gt;&gt; bookSnapshot =
        firestore.collection('books').snapshots();
  StreamBuilder&lt;QuerySnapshot&gt;(
     stream: bookSnapshot,
     builder: (context, snapshot) {
     ...
     }
  ),
  </code></pre>
  <p>I m fairly new to this concept, and I really need help on how to un-subscribe to the stream.</p>
  <p>Any help is greatly appreciated, thank you!</p>