Order Data only by Price in Flutter Firebase

Viewed 123

Query:

FirebaseFirestore.instance.collection('products')
  .where('dateOfExpiry', isGreaterThanOrEqualTo: DateTime.now())
  .orderBy('dateOfExpiry')
  .orderBy('price', descending: false);

I'm using Flutter with Firebase to fetch data from a collection of products. My condition here is to fetch data of the products which are not expired in order from lowest price to highest price. But I don't want to order it by the date of expiry. As in flutter, I need to put order by on the column for which I'm using inequality operator i.e. "dateOfExpiry".

Otherwise I get this error:

The initial orderBy() field "[[FieldPath([price]), false]][0][0]" has to be the same as the where() field parameter "FieldPath([dateOfExpiry])" when an inequality operator is invoked. 'package:cloud_firestore/src/query.dart': Failed assertion: line 252 pos 18: 'field == orders[0][0]'

Any solution for this will be appreciated.

0 Answers
Related