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
  • 56
  • 7

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 Chowdhury
  • 1,348
  • 6
  • 15