0

This query works without the orderBy. Am I doing this wrong? The start and end are set like this:

final startTs = Timestamp.fromMicrosecondsSinceEpoch(
    pickedStartDate.microsecondsSinceEpoch,
  );

I also included an image with the database value

This is what _buildStream() returns

FirebaseFirestore.instance
          .collection("content")
          .where("active", isEqualTo: true)
          .where("member", isEqualTo: false)
          .where("end", isGreaterThanOrEqualTo: DateTime.now())
          .orderBy("start", descending: true)
          .snapshots();

Used in a Streambuilder:

StreamBuilder<QuerySnapshot>(
        stream: _buildStream(),
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasError) {
            return Text('Error: ${snapshot.error}');
          }

          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return Center(child: CircularProgressIndicator());
            default:
              print(snapshot.data);
              final _content = snapshot.data.docs
                  .map((data) => ContentModel.fromFirestore(data))
                  .toList();

Error:

flutter: The getter 'docs' was called on null.
flutter: Receiver: null
flutter: Tried calling: docs

enter image description here

William
  • 884
  • 2
  • 12
  • 23
  • Please post where `docs` used – Ashish Jul 24 '21 at 11:58
  • @William similarly to previous threads, [I can't use orderBy query from firestore if where is used Flutter](https://stackoverflow.com/questions/65956791/i-cant-use-orderby-query-from-firestore-if-where-is-used-flutter), [Firestore query orderBy not working?](https://stackoverflow.com/questions/51434167/firestore-query-orderby-not-working?rq=1) did you create a compound index? – Farid Shumbar Jul 26 '21 at 08:47

0 Answers0