【发布时间】:2021-08-01 08:15:06
【问题描述】:
我正在尝试使用 Streambuilder 从 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
【问题讨论】:
-
请提供异常信息。
-
@hacker1024 考虑查看更新的问题,我添加了捕获的异常
标签: flutter dart stream-builder flutter-sliver customscrollview