0

Hi When I get the data from Firebase, it gives an error. The codes are as follows. where do you think i am going wrong

    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"];

codes in data list:

Row(
                                      children: [
                                        Spacer(),
                                        Text(
                                          DateFormat("dd/MM/yyyy").format(
                                            data["aciklamaDate"].toDate()
                                          ),
                                          style: TextStyle(
                                            color: Colors.black
                                                .withOpacity(0.5),
                                          ),
                                        )
                                      ],
                                    ),
  • 1
    Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt Jan 15 '22 at 11:41
  • hi @nvoigt Thank you. But I couldn't quite figure it out. – Yunus Dikenlitarla Jan 15 '22 at 11:54

1 Answers1

1

Either>

snapshot["aciklamaDate"].toDate()

or

data["aciklamaDate"].toDate()

calls toDate() on a null value.

Since you have the full stacktrace, you should be able to say which on it is.

That means that in the map, "aciklamaDate" does not exist. Why? Well, that is for you to find out.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • `"aciklamaDate": aciklamaDate ?? FieldValue.serverTimestamp(), ` If the user does not enter a date in the section, it automatically assigns a date from the system. Is the problem from there? – Yunus Dikenlitarla Jan 15 '22 at 12:30
  • 1
    No... it's the part where you get it back and it's null. – nvoigt Jan 15 '22 at 13:03