title: how to have query in flutter based upon the conditions?
body: <p>I want to have queries processed for <code>StreamBuilder&lt;QuerySnapshot&gt;</code> based on certain conditions which I am not able to do. Below are the queries coded</p>
  <pre><code>    Query query;
      if (a==b){
      query = Firestore.instance.collection('collection1');
      }
      
      else if (c==d){
      query = Firestore.instance.collection('collection2');
      }
      else if (e==f){
      query = Firestore.instance.collection('collection3');
      }
  </code></pre>
  <p>Inside Widget Build</p>
  <pre><code>StreamBuilder&lt;QuerySnapshot&gt;(
  
      stream: query.snapshots(),
      builder: (context,snapshot){
        if (!snapshot.hasData){
          return Text(&quot;Loading&quot;);
        }
  
        return ListView.builder(
            itemCount: snapshot.data.documents.length,
            itemBuilder: (context, index){
  
              String names = snapshot.data.documents[index]['name'];
              List steps = List.castFrom(snapshot.data.documents[index][&quot;steps&quot;])
  
  
              return NameCard(names: names,steps: steps);
  
            });
      },
  
    )
  </code></pre>
  <p>I need to switch the queries after the conditions are checked and then the query which is satifying the conditions of <code>if-else</code> shall proceed further to make the things happen <code>StreamBuilder&lt;QuerySnapshot&gt;</code> but if there is only one query it works perfectly fine. but when I tried to switch queries depending upon the conditions it does not work, it gives error of null snapshot.</p>
  <p>How should I achieve it to switch the queries based upon the conditions?</p>