NoSuchMethodError (NoSuchMethodError: The method 'toDate' was called on null. Receiver: null Tried calling: toDate())

NoSuchMethodError (NoSuchMethodError: The method 'toDate' was called on null. Receiver: null Tried calling: toDate())

您好,当我从 Firebase 获取数据时,出现错误。代码如下。你认为我错在哪里

    Map<String, dynamic> toMap() {
    return {
      "aciklama": aciklama,
      "fiyat": fiyat,
      "aciklamaDate": aciklamaDate ?? FieldValue.serverTimestamp(),
      "kim": kim,
    };
  }

  Vergi.fromMap(DocumentSnapshot snapshot)
      : aciklama = snapshot["aciklama"],
        fiyat = snapshot["fiyat"],
        aciklamaDate = snapshot["aciklamaDate"].toDate(),
        kim = snapshot["kim"];

数据列表中的代码:

Row(
                                      children: [
                                        Spacer(),
                                        Text(
                                          DateFormat("dd/MM/yyyy").format(
                                            data["aciklamaDate"].toDate()
                                          ),
                                          style: TextStyle(
                                            color: Colors.black
                                                .withOpacity(0.5),
                                          ),
                                        )
                                      ],
                                    ),

或者>

snapshot["aciklamaDate"].toDate()

data["aciklamaDate"].toDate()

对空值调用 toDate()

既然你有完整的堆栈跟踪,你应该能够说出它是哪一个。

这意味着在地图中,“aciklamaDate”不存在。为什么?好吧,那就等着你去发现了。