i trying to get a string/check a string for a validation in my flutter app. i've been trying to use the .where() function but they gave me this error when i did it
The argument type 'Future<QuerySnapshot<Object?>>' can't be assigned to the parameter type 'Future<DocumentSnapshot<Object?>>?'
this is the code that give me the error
final phoneNumber = ModalRoute.of(context)!.settings.arguments as String;
CollectionReference users = FirebaseFirestore.instance.collection('users');
return FutureBuilder<DocumentSnapshot>(
future: users.where("phoneNumber", isEqualTo : phoneNumber).get(),
builder:
(BuildContext context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return const Text("Something went wrong");
}
if (snapshot == null || !snapshot.data!.exists) {
return const Text("data doesn't exist");
}
if (snapshot.hasData) {
return const Text("data exist already");
}
if (snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> data =
snapshot.data!.data() as Map<String, dynamic>;
return Text("Full Name: ${data['full_name']} ${data['last_name']}");
}
return const Text("loading");
},
);
been trying and searching for 3-4 hours but all the reference tell me that i need to input the unique id
that will look like this
final docSnapshot = await Firestore.instance
.collection("$Friseur/1/$Tag/1/$Uhrzeit")
.document(${doc_id_here})
.get();
if(docSnapshot.exists) {
setState(...)
}
else {
setState(...)
}
CodePudding user response:
Add doc function with document id after where function because future parameter accept Future<DocumentSnapshot<Object?>>?
future: users.where("phoneNumber", isEqualTo : phoneNumber).doc(documentId).get(),
CodePudding user response:
Change FutureBuilder<DocumentSnapshot> to FutureBuilder<QuerySnapshot>
when you use where operation it return the QuerySnapshot.