I have multiple collections in flutter firebase. For example, collection(A), collection(B), I want to show the data in these multiple collections as a single list on my homepage. Is there a way to this?
Thanks in advance
I have multiple collections in flutter firebase. For example, collection(A), collection(B), I want to show the data in these multiple collections as a single list on my homepage. Is there a way to this?
Thanks in advance
There's no way combining Firestore queries from multiple collections into one query. If you really want to keep the data in two different collections, you should create two separate queries. After creating, you have to merge two separate queries. You can find more information about this here.
It would be easier for you to change your Firestore Data Structure and store the two collection into one collection instead. After changing your Firestore Data Structure, you can then query like e.g. below:
FirebaseFirestore.instance
.collection('products')
.where('productType', whereIn: <String>['product1', 'product2']);
You could also check Firestore Data Stucture guide here.
I don't think so, since each stream builder will subscribe to one collection to show its documents. Maybe it's better to make Lists on the same screen separated by Text or any sized box widget.