首页 > 解决方案 > 用于空值的空检查运算符,类型“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 {
//
//                                  }
                              },
                            ),

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


推荐阅读