I want to retrieve All Add_product data using current user uid How is it possible.
My code return only loading widget because my query is incorrect. How can I write my query in a correct way?
My database:
My code
StreamBuilder(
stream: FirebaseFirestore.instance.collectionGroup("Add_product").where("id",isEqualTo: FirebaseAuth.instance.currentUser!.uid).snapshots(),
builder:(BuildContext context,AsyncSnapshot<QuerySnapshot>snapshot){
if (!snapshot.hasData) {
return Center(child: LoadingAnimationWidget.staggeredDotsWave(color: Colors.red, size: 10));
}
` return Container(
child: InkWell(
child: Card(
elevation:5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(9.0),
child: Image.network(snapshot.data!.docs[index]["url"],width: MediaQuery.of(context).size.width*.49,height:MediaQuery.of(context).size.height*.17 ,),
),
SizedBox(height: 7,),
Text(
snapshot.data!.docs[index]["product_name"],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
textAlign: TextAlign.center,
),
SizedBox(height: 4),
);
},
),
);
}
),
2
Answers
Try this one
If you also need user id, you can get the userId first and store it into the variable and pass that variable into
where
In my perspective the
firebase
structure which you are following is not recommended, consider changing it.To answer your question, you can try: