【发布时间】:2022-11-14 05:41:07
【问题描述】:
我学习 Flutter 已经有一段时间了,试图从现有的 Flutter 项目中理解,所以后面的代码不是我的。
目前我正在测试一个项目,但我面临一个我从未见过的错误。
The getter 'length' was called on null.
Receiver: null
Tried calling: length
我认为它来自这部分代码。
StreamBuilder<List<DocumentSnapshot>>(
stream: postListBloc.postStream,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting)
return Center(
child: CircularProgressIndicator(),
);
else {
int presentLength = snapshot.data.length;
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
DocumentSnapshot documentSnapshot =
snapshot.data[index];
String id = documentSnapshot.id;
debugPrint('${snapshot.data.length}');
return Column(children: [
Padding(
padding: EdgeInsets.only(bottom: 10),
child: PostCardView(
documentSnapshot.get('community'),
id,
true)),
(index != snapshot.data.length - 1)
? Container()
: buildProgressIndicator(presentLength)
]);
});
}
},
),
我在这里搜索了不同的解决方案,但到目前为止没有任何效果。
如果有人知道如何解决这个问题。
【问题讨论】:
-
试试
else if(snapshot.hasData){ int presentLength = snapshot.data.length;
标签: flutter