我有这段代码,我想返回一个documentshapshot流。
/* Get Firestore products docs
*/
Stream<List<DocumentSnapshot>> fetchFirstProductListStream() {
....
return getFirestoreUserStream(loggedInUser.uid).map((UserModel rad) =>
(geo
.collection(collectionRef: collectionReference)
.within(center: center, radius: rad.radius, field: field)) as List<DocumentSnapshot>
);
}当我尝试将返回值转换为List时,我确实得到了以下错误。
> [VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: type
> '_AsBroadcastStream<List<DocumentSnapshot>>' is not a subtype of type > > 'List<DocumentSnapshot>'发布于 2021-04-17 20:24:07
您有两个选项:
Option1:,因为您最终已经将数据转换为普通列表。直接返回。您现在不需要Stream或StreamBuilder来解析它。您可以直接使用ListView.builder()来呈现数据:
List<DocumentSnapshot> fetchFirstProductListStream() {
....
return getFirestoreUserStream(loggedInUser.uid).map((UserModel rad) =>
(geo
.collection(collectionRef: collectionReference)
.within(center: center, radius: rad.radius, field: field)) as List<DocumentSnapshot>
);
}选项2:从接口返回一个真正的Stream,并使用StreamBuilder异步读取它:
签出此SO Post
https://stackoverflow.com/questions/67136023
复制相似问题