fetchLeaderboard static method

Future fetchLeaderboard({
  1. required HMSPoll poll,
  2. required int? count,
  3. required int startIndex,
  4. required bool includeCurrentPeer,
})

fetchLeaderboard method is used to fetch leaderboard for a quiz

Parameters

hmsPoll - hmsPoll object of the quiz for which leaderboard needs to be fetched

count - count of the peers in the rankings

startIndex - startIndex from where the leaderboard rankings needs to be fetched

includeCurrentPeer - includeCurrentPeer whether to include the local peer in the leaderboard rankings

Returns

Future

Refer fetchLeaderboard

Implementation

static Future<dynamic> fetchLeaderboard(
    {required HMSPoll poll,
    required int? count,
    required int startIndex,
    required bool includeCurrentPeer}) async {
  var result = await PlatformService.invokeMethod(
      PlatformMethod.fetchLeaderboard,
      arguments: {
        "poll_id": poll.pollId,
        "count": count,
        "start_index": startIndex,
        "include_current_peer": includeCurrentPeer
      });

  if (result != null) {
    if (result["success"]) {
      if (result["data"] != null) {
        return HMSPollLeaderboardResponse.fromMap(result["data"]);
      } else {
        return null;
      }
    } else {
      if (result["data"]["error"] != null) {
        return HMSException.fromMap(result["data"]["error"]);
      }
    }
  }
}