是否有使用async*和yield*或不返回FirebaseFirestore querysapshot的区别



第一种情况和第二种情况有什么区别吗?

1。

Stream<QuerySnapshot> streamUsersOne() async* {
yield* FirebaseFirestore.instance.collection('users').snapshots();
}

2。

Stream<QuerySnapshot> streamUsersTwo() {
return FirebaseFirestore.instance.collection('users').snapshots();
}

第一个(async*和yield)是在创建自己的流时使用的,这里不需要使用它,因为快照方法已经返回了流的类型。你可以观看这个片段来了解更多关于如何创建一个流。

最新更新