title: Kotlin coroutines and Android - get the result of a Firestore query Task result
body: <p>I'm writing a function that does a query on firestore documents, and returns them in a list. If there are no documents, return null (or an empty list). I'm not very familiar with Kotlin, I only know Flutter</p>
  
  <p>Kotlin code (what I tried) but it's saying I cannot return inside the listener:</p>
  
  <pre><code>fun getPlaces(type: String): List&lt;DocumentSnapshot&gt;? {
          db.collection("users")
              .whereEqualTo("type", type)
              .get()
              .addOnSuccessListener { documents -&gt;
                  if (documents.isEmpty) {
                      return null
                  } else {
                      return documents
                  }
              }
              .addOnFailureListener { exception -&gt;
                  Log.w(TAG, "Error getting documents: ", exception)
              }
      }
  </code></pre>
  
  <p>Here's the Flutter equivalent of what I'm trying to do:</p>
  
  <pre><code>List&lt;DocumentSnapshot&gt; getDocs(String type) async {
      QuerySnapshot snaps = await db.collection('users').where('type', isEqualTo: type).getDocuments();
  
      if (snaps.documents.isEmpty) {
          return null;
      } else {
          return snaps.documents;
      }
  }
  </code></pre>
  
  <p>Syntax might be a little off but something like that</p>