0

How I can order data doc by two field, My app have a stream builder and I want order the data by the time that wrote and if the todo important so there is two field in docs one for time and there is boolen value i want the data order by the time and if the data important that is mean the boolen true to be in the top of the list of stream and when i add data will show ender it. this the code I used for strem

final FirebaseFirestore firestore;
  DataBase({this.firestore});
  Stream streamTodos({String uid}) {
    try {
      return firestore
          .collection("homeNeeds")
          .doc(uid)
          .collection('homeNeeds')
          .orderBy('time', descending: true)
          .snapshots();

    
    } catch (e) {
      return e;
    }
  }

// i tried to put tow orderBy('time', descending: true).orderBy('pin', descending: true) and it doesn't work the snap shot return empty

3 Answers 3

0

it appears that is not as simple as saying you can or you can not, it depends on your specific case, but most likely you'll have to do it client-side.

There is another question like this one here:

Sign up to request clarification or add additional context in comments.

Comments

0

You can use multi_sort: ^3.0.0 in this case.

https://pub.dev/packages/multi_sort

Comments

0

I solved this problem by adding Indexes in cloud firestore and that option allow you to use tow orderby in the same code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.