Home > other >  How to make a method of sorting by tags from Firebase
How to make a method of sorting by tags from Firebase

Time:10-30

enter image description here I will be grateful for every answer

I didn't even know where to start, because nothing comes to mind at all, i will be grateful for every answer

CodePudding user response:

so I'm going to follow the steps for you, we have a collection named stocks :

final CollectionReference stocks = FirebaseFirestore.instance.collection('stocks')

you want to filter the documents of this collection for each tag, meaning for each tag in your application, you want to show where that tag is inside the document's tags so before you call the get() filter them with what you want :

final pizzaDocumentsQuery = stocks.where("tags", arrayContains: "pizza");

this will filter them based on what documents have the pizza tag in the tags list

then, you can call get() to load them from the firestore database :

QuerySnapshot pizzaDocuments = await pizzaDocumentsQuery.get();

that's it, you have it.

Hope this helps you.

  • Related