title: How to call different Flutter functions based on firebase querySnapshot result
body: <p>Using Flutter, I would like to search a Firebase collection (Collection X) to find out if a field  (Field Y) exists in any document in said collection. If the document containing the field exists I would like to perform a task ( Task A ), If a document containing the field doesn't exist I would like to perform a different task ( Task B).</p>
  <p>Here's what I've tried:</p>
  <pre><code>final CollectionReference collectionXRef = FirebaseFirestore.instance.collection(&quot;Collection X&quot;)
  
  collectionXRef.where(&quot;Field Y&quot;, isEqualTo: Z)
                    .get().then((QuerySnapshot querySnapshot) {
                  if (querySnapshot.docs.length &gt; 0) {
                     Task A
                  }
                  else { Task B }
  })
  
  
  </code></pre>
  <p>The issue I'm having is that no matter what I put in the If statement: <code>(querySnapshot.docs.length &gt; 0)</code> The code keeps performing Task A</p>
  <p>Here's what I've tried:</p>
  <pre><code>if (querySnapshot.docs.isEmpty)
  
  if (querySnapshot.docs.isNotEmpty) 
  
  if (querySnapshot.docs.length &gt; 0) 
  
  if (querySnapshot.docs.length != 0)
  
  if (querySnapshot.size &gt; 0)
  
  if (querySnapshot.size != 0)
  
  if (querySnapshot.size == 0)
  
  if (querySnapshot.size &gt;= 1)
  
  
  </code></pre>
  <p>Desired behavior:  I want to perform &quot;Task B&quot; if there is no document In the collection that contains the searched field, however, the function always returns Task A, which work fine if there are results to display, but, If there aren't any results it shows a blank results page instead of performing Task B.</p>
  <p>The collection &quot;FbCollection1&quot; has only 3 documents in it, 2 out of those 3 documents contain the field being searched for &quot;Field Y&quot;. Nither the documents nor the searched field &quot;Field Y&quot; are nested.</p>