firebase - 颤动的火力库检索数据快照时出错.data.docs.length
问题描述
我正在使用流生成器从 firestore 中的 flutter firebase 中检索数据,但在snapshot.data.docs.lengt
. 如果您能帮我解决,我将不胜感激。
这是我的代码
StreamBuilder(
stream: FirebaseFirestore.instance
.collection(
'Showrooms/${ConstantsFirebaseMethods.getCurrentUserId()}/Vehicles')
.snapshots(),
builder: (_, snaphot) {
print(
'currentUserId ${ConstantsFirebaseMethods.getCurrentUserId()}');
return GridView.builder(
scrollDirection: Axis.vertical,
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200, mainAxisSpacing: 10),
itemCount: snaphot.data.docs.length,
itemBuilder: (BuildContext ctx, index) {
print(
' here is levelName ${snaphot.data.docs[index].get('name')} and levelDuration ${snaphot.data!.docs[index].get('duration')}');
return InkWell(
onTap: () {},
child: Container(
margin: EdgeInsets.only(
top: 8.0, left: 8.0, right: 8.0),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.8),
spreadRadius: 2,
blurRadius: 3,
offset: Offset(
0, 3), // changes position of shadow
),
],
borderRadius:
BorderRadius.all(Radius.circular(25.0)),
color: Colors.white,
),
padding: EdgeInsets.only(top: 50.0),
width: MediaQuery.of(context).size.width * 0.6,
height: MediaQuery.of(context).size.height * 0.20,
child: Column(
children: [
Container(
child: Text(
'${snaphot.data.docs[index].get('name')}',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 26.0),
),
),
Container(
child: Text(
'${snaphot.data.docs[index].get('duration')}',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0),
),
),
],
)),
);
});
}),
解决方案
推荐阅读
- python - 基于数据框值的相同颜色和不同色调的散点图
- devexpress - 响应式 Web 应用程序模板用户/注册实现 asp.net Web 表单
- python - 通过特定的网络接口发出 Python 请求
- node-red - 将 msg.payload 作为值插入 LIFX 节点
- sas - 打印二维表
- npm - npm package-lock.json 中的完整性字段实际上是做什么用的?
- typescript - 如何访问 serverless.ts 中无服务器 cli 传递的选项值?
- django - psycopg2.OperationalError:无法翻译主机名“db”(虽然名称“db”在容器中可 ping)
- c# - 在链表中查找值
- r - 如何过滤滑块中闪亮传单中的年份(交互式地图)