I had a use case where I wanted to validate a code entered against a field inside a Firestore collection document. My goal was to get a true/false response. It’s easy to check if the document exists, but I struggled when trying to find if the value exists inside a specific field…
Enter Custom Actions…
Here’s the custom action code I used, then I just run the custom action with the textinput provided and get a boolean response.
Future checkIfCodeExists (String CODETOCHECK) async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection('COLLECTION_NAME')
.where('CODE FIELD NAME', isEqualTo: CODETOCHECK)
.limit(1)
.get();
return querySnapshot.docs.isEmpty;
}