Hari A.R
Hari A.R

Reputation: 27

flutter How to Get Bool value from firestore and change the button state

This is My Demo Data From Firestore How Can Retrieve the bool value

Upvotes: 0

Views: 260

Answers (1)

Greg Fenton
Greg Fenton

Reputation: 2808

Firestore is a Document Store Database. The operations available to you are to find/read, create, update and delete individual and ENTIRE documents (think: JSON objects) at a time.

There is no API to fetch/read just a single field within an existing document. Rather, you need to read the document (the JSON object), and then use whichever field(s) from that document that you wish.

So in your example you would do something like (pseudo-code below):

const getDocumentFromItsId = async (id) => {
  try {
    // fetch the document
    let docRef = FIRESTORE.db.collection("User Information").doc(id);
    let docSnap = await docRef.get();
    let docData = docSnap.data();

    return docData.applied;  // will return boolean value or null

  } catch (ex) {
      console.error(`EXCEPTION while reading doc id(${id}):`, ex);
  }
}

Upvotes: 1

Related Questions