I have a Flutter project that uses Cloud Firestore. In one of my widgets, I have a StreamBuilder that ideally reads snapshots from the database. In theory, my API for reading from a remote server should be abstract enough to swap Firestore out with a different implementation.
class Database {
Stream<QuerySnapshot> get snapshots => Firestore.instance.collection('entires').snapshots();
Stream<List<String>> get entries => snapshots.map((snapshot) => snapshot.documents.map((document) => document.data['name']).toList());
}
If my StreamBuilder uses snapshots
, then AsyncSnapshot<QuerySnapshot>
has data (hasData
returns true).
If my StreamBuilder uses entries
, then AsyncSnapshot<List<String>>
will never have data (hasData
returns false)---even if I successfully printed out what the data is (my return result is a populated list of strings).
I hope to keep my Database
interface free of Firestore. So, my question is: why does StreamBuilder's AsyncSnapshot return nothing even if I have data?