2

On the Read Data example of Firestore this link I don't understand why it is necessary to include de snapshot.hasData to prove that the document does not exist.

if (snapshot.hasData && !snapshot.data!.exists) {
          return Text("Document does not exist");
        }
Andres R
  • 193
  • 2
  • 7
  • 3
    In addition to Victor's excellent answer, I recommend checking out this answer on the different types of snapshots you may encounter: https://stackoverflow.com/questions/65874202/what-is-the-difference-between-existing-types-of-snapshots-in-firebase/65874916#65874916 – Frank van Puffelen Sep 13 '21 at 13:54

1 Answers1

4

So .hasData is called to be sure the DocumentSnapshot from Firestore is available (a DocumentSnapshot is returned whether or not the document exists) and .exists is called to figure out if the document does exists.

Victor Eronmosele
  • 7,040
  • 2
  • 10
  • 33