title: Flutter - Sorting Cloud Firestore
body: <p>I am trying to sort the listview that is coming in. Since this listview is images, I added a number to the firestore object so I can sort ascending.</p>
  
  <p>I cannot seem to get the items to sort, and I am sure its how I built the app.</p>
  
  <p>I tried to add the .orderBy() to the collection, however its says Query is not a type of CollectionReference.</p>
  
  <p>Here is my page</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'dart:async';
  import 'package:cloud_firestore/cloud_firestore.dart';
  
  class Events extends StatefulWidget {
    @override
    _EventsState createState() =&gt; _EventsState();
  }
  
  class _EventsState extends State&lt;Events&gt; {
    StreamSubscription&lt;QuerySnapshot&gt; subscription;
  
    List&lt;DocumentSnapshot&gt; snapshot;
  
    CollectionReference collectionReference =
    Firestore.instance.collection("Events");
  
  
    @override
  
    void initState() {
      subscription = collectionReference.snapshots().listen((datasnapshot) {
        setState(() {
          snapshot = datasnapshot.documents;
        });
      });
      super.initState();
    }
  
  //  passData(DocumentSnapshot snap) {
  //    Navigator.of(context).push(
  //        MaterialPageRoute(builder: (context) =&gt; EventPage(snapshot: snap,)));
  //  }
  
    Widget build(BuildContext context) {
      return Scaffold(
           backgroundColor: Colors.white,
        body: Column(
          children: &lt;Widget&gt;[
            Container(
              width: MediaQuery.of(context).size.width,
              height: 200,
              decoration: BoxDecoration(
                image: DecorationImage(
                  fit: BoxFit.fill,
                  image: AssetImage("assets/images/events.jpg"),
                ),
              ),
            ),
            Divider(
              color: Colors.black,
            ),
            Expanded(
              child: ListView.separated(separatorBuilder: (context, index) =&gt; Divider(color: Colors.black12,
      ), itemCount: snapshot.length,
      itemBuilder: (context, index){
                return Card(
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: 210,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        fit: BoxFit.fill,
                        image: NetworkImage(snapshot[index].data["image"]),
                      ),
                    ),
                  ),
  
                );
      }
  
            ))
          ],
        ),
      );
    }
  }
  </code></pre>
  
  <p>I really would like to sort these images by predetermined numbers in teh database.</p>