我试图在 a和 aStreambuilder
中显示检索到的数据时使用 Firebase firestore 监听实时文档,但是当我这样做时,列表中断并且屏幕保持空白。CustomScrollView
SliverList
我尝试了一个FutureBuilder
并且它有效,但它不能满足我的要求。
这是我为流构建器编写的代码:
Widget sliverList() {
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.transparent,
expandedHeight: 220.0,
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.parallax,
background: Column(
children: [Daily(), AddPost()],
),
),
),
StreamBuilder<QuerySnapshot>(
stream: feedServices.listenToFeedinStream(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
return SliverFixedExtentList(
itemExtent: 500,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (snapshot.hasData) {
Post post = Post.fromMap(snapshot.data.docs[index].data());
return Column(
children: [
FeedItem(
thread: post,
),
seperator()
],
);
} else if (!snapshot.hasData) {
return Text('no data');
} else if (snapshot.hasError) {
return Text('has err');
} else {
return Text('not specified');
}
},
childCount: snapshot.data.docs.length,
),
);
})
],
);
}
捕获的异常:
flutter: The following NoSuchMethodError was thrown building StreamBuilder<QuerySnapshot>(dirty, state:
flutter: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#da6d3):
flutter: The getter 'docs' was called on null.
flutter: Receiver: null
flutter: Tried calling: docs