firebase - 用于空值的空检查运算符,类型“String”不是“index”类型“int”的子类型
问题描述
我正在尝试从 firebase 获取数据并使用卡片在屏幕上显示它。但我遇到了以下错误:
Null check operator used on a null value
type 'String' is not a subtype of type 'int' of 'index'
这两个错误我都追溯到以下代码片段。ListView 的子部分显示了我认为的错误。关于我应该改变什么的任何建议?
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('orders')
.where('SalonID', isEqualTo: widget.aadhar)
.where('Status', isEqualTo: "1")
.snapshots(),
builder: (context, snapshot) {
return ListView(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
children: snapshot.data.docs
.asMap()
.map((index, DocumentSnapshot document) {
getCustomerDetails(
document['CustomerID']);
DateTime bookingdate = DateTime.parse(
document['BookingDate']);
num total = 0;
List<dynamic> services =
document['Requested_Service'];
services.forEach((element) {
total += element['price'];
});
return MapEntry(
index,
AppointmentCard(
paymentMode: document['payment'],
// paymentMode: document['payment'],
date:
'${bookingdate.day.toString()}-${bookingdate.month}-${bookingdate.year}',
price: "$total",
orderid: document['OrderID'],
onPressed: () {
print("Hello");
_showMyDialog();
},
isCompleted: document['Status'],
name: customerDetails[index]
['Name'],
contact: customerDetails[index]
['Contact'],
services: Flexible(
child: ListView.builder(
shrinkWrap: true,
padding:
const EdgeInsets.all(8),
itemCount: document[
'Requested_Service']
.length,
itemBuilder:
(BuildContext context,
int index) {
return Text(document[
'Requested_Service']
[index]['name']);
}),
),
),
);
})
.values
.toList(),
);
// if (ordersList.isEmpty) {
// return SpinKitThreeBounce(
// color: Colors.red,
// );
// } else {
//
// }
},
),
解决方案
推荐阅读
- reactjs - ncaught Invariant Violation:对象作为 React 子对象无效
- reactjs - 选择锚链接 React 和 Gatsby 后关闭菜单
- html - 如何将 Chrome 的本机 loading="lazy" 应用于我的所有图像?
- java - String 到 int 数组的转换是否可行?
- istio - 特使代理中的多个完全匹配
- automated-tests - 使用 TV4 的 Postman 模式验证
- java - 将图像上绘制的形状写入 PDF 文件时会反转第 2 部分
- sql - 从具有相似 ID 和前缀的另一行复制字段
- reactjs - 触发从组件外部打开全屏对话框,打开时如何关闭对话框
- authentication - SSLSocket.startHandshake 是否包含 SSLSocket 的证书验证和主机名验证?