snapshots()
返回
Stream<Query>
是的。以同样的方式
await
函数返回
Future
,你可以
await for
所有的值(可以是零,一个或多个)都是
Stream
产生,例如:
Future findBarcode() async {
String searchBarcode = await BarcodeScanner.scan();
String idOfBarcodeValue;
Stream<Query> stream = Firestore.instance
.collection('${newUser.userLocation}')
.where('barcode', isEqualTo: '${searchBarcode}')
.snapshots();
await for (Query q in stream) {
idOfBarcodeValue = q.documents[0].documentID;
}
print(idOfBarcodeValue);
// if the stream had no results, this will be null
// if the stream has one or more results, this will be the last result
return idOfBarcodeValue;
}