简体   繁体   中英

How can I sort a collection in Firebase with Flutter?

I'm trying to display a leaderboard system with Flutter by storing different users' high scores inside of Firebase and I'm having trouble figuring out how to sort the users so only the top 10 show up in the collection that have a score below the user's. So far I got it so it limits it to just the top ten highest scores overall but I can't get it to show the top ten for just the ones that have a score less than the user.

// Get Users stream
Stream<List<HighscoreData>> get score {
    return scoreCollection
        .orderBy('score', descending: true,).limit(5)
        .snapshots()
        .map(_scoreListFromSnapshot);
}

lets try this one its will work for yo u

Firestore.instance
         .collection("users")
         .orderBy('score', descending: true,).getDocuments()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM