0

I am trying to short "realtime database" result according to "date" in flutter. But I cant use multiple orderByChild('child_name'). It throw an error. My code is

final String path = 'jsondata';
final _dbRef = FirebaseDatabase.instance.reference();
_dbRef.child(path)
.orderByChild('trade_code').equalTo('GP')
.once()
.then((DataSnapshot snapshot) {
  snapshot.value.forEach((key, value) {
    print(value);
  });
});

The result is Result

Now I want to sort the data by Date. How can I do that?

Nasar
  • 66
  • 1
  • 8

1 Answers1

0

It's not possible to use multiple oder at the same time in Firebase Realtime Database. Please check the following doc:

Firebase Realtime Database Query

To achieve that type of complex query I prefer that you should migrate from the Realtime Database to Firebase Cloud Firestore. Check the following resource:

Simple and Complex Dynamic Query in Could Firestore

Your Firestore instance would be:

FirebaseFirestore.instance
.collection('products')
.where('trade_code', isEqualTo: 'GP')
.orderBy('date')
Amon C
  • 1,710
  • 9
  • 17
  • I tried to make the query using cloud Firebase. But it doesn't work. Can you please make a query with where and order by with same time? – Nasar Sep 10 '20 at 01:46
  • I edited the answer code. See the last portion. Did you get any error? – Amon C Sep 10 '20 at 15:22