ORDER by recent to old

609 views
Skip to first unread message

Mahmoud Alminawi

unread,
May 7, 2020, 11:29:55 PM5/7/20
to Flutter Development (flutter-dev)
Hello guys,
I have a list of images that i would like the pictures to show from new to old. I tries doing ".orderBy("timestamp"), where timestap is the time. It shows from old to new. Is there a way to make it so it shows from new to old?
Please help! 
Thanks a lot.


getImagesByFolderAndUserId(User user, String folderId) {
return Firestore.instance
.collection(APIConstants.FIRESTORE_IMAGES_COLLECTION_NAME).orderBy("timestamp") // that is what i added
.where(
"userid", isEqualTo: user.uid)
.where(
"folderid", isEqualTo: folderId)
.snapshots();
}

redbr...@google.com

unread,
May 8, 2020, 1:04:12 AM5/8/20
to Flutter Development (flutter-dev)
The orderBy method has an optional bool parameter called "descending" that will reverse the order for you:


-Andrew

Mahmoud Alminawi

unread,
May 8, 2020, 7:34:27 PM5/8/20
to Flutter Development (flutter-dev)
Thank you very much for your reply. 
It worked however, i get this in the console.
Does this matter?

W/Firestore(12903): (21.3.0) [Firestore]: Listen for Query(buckets where userid == 6YuA4xNzJ3hyyTRcCuLOkxmectz2 and folderid == 1zLOVfSwZDLXOHymKObj order by -timestamp, -__name__) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/create_composite=ClFwcm9qZWN0cy9waG90b2J1Y2tldC04NDJhMy9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvYCghmb2xkZXJpZBABGgoKBnVzZXJpZBABGg0KCXRpbWVzdGFtcBACGgwKCF9fbmFtZV9fEAI, cause=null}
I/System.out(12903): com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/photobucket-842a3/firestore/indexes?create_composite=ClFwcm9qZWN0cy9waG90b2J1Y2tldC04NDJhMy9

Suzuki Tomohiro

unread,
May 8, 2020, 7:50:50 PM5/8/20
to Flutter Development (flutter-dev)
I expected it fails when Firebase shows that message. 



--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f70ed3a5-599c-497f-bccb-1733c2ba37a7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages