This is the screenshot of my database.
I want to fetch the record for a particular username. (For eg: where [email protected]) Can anyone suggest to me how to fetch this in flutter?
It would be a great help, Thank you.
This is the screenshot of my database.
I want to fetch the record for a particular username. (For eg: where [email protected]) Can anyone suggest to me how to fetch this in flutter?
It would be a great help, Thank you.
To get the data, you can create a function like:
Future getData(String username) async {
List dataList = [];
try {
await FirebaseFirestore.instance.collection('userdata').where('user', isEqualTo: username).get().then((QuerySnapshot querySnapshot) => {
querySnapshot.docs.forEach((doc) {
itemList.add(doc.data());
}),
});
return itemList;
} catch (e) {
print(e.toString());
return null;
}
}
When you'll call this function, you will have to pass the username and it would return a list of data items.
This list can then be used to show data in the UI as:
child: Text(
title: Text(subjectList[index]['user']),
),
you can try this approach it helped me, but if you have migrated to null safety just make sure that you change the code accordingly
You can try the following query to get your result.
FirebaseFirestore.instance
.collection('your-collection-name')
.where('user', arrayContains: '[email protected]')
.get();
user key values from the firebase collection. You can simple use the same query without the condition statement arrayContains: email. Future<QuerySnapshot> user = FirebaseFirestore.instance .collection('userdata') .where('user').get();FirebaseFirestore.instance .collection('userdata') .where('weight').get();Instance of 'Future<QuerySnapshot<Map<String, dynamic>>>'For android solution follow this:
FirebaseFirestore.getInstance()
.collection("users").whereArrayContains("user","[email protected]").get();