Understanding FirebaseFirestore Read Data example

Viewed 52

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");
        }
1 Answers

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.

Related