getLeaderboard method

Future<List<LeaderBoardDriver>> getLeaderboard(
  1. int offset,
  2. int length
)

Retrieves a paginated list of drivers from the getLeaderboard.

The getLeaderboard ranks drivers based on their driving performance metrics within the same company/account group.

Parameters:

  • offset: Starting position in the getLeaderboard (0-based)
  • length: Number of drivers to retrieve

Returns:

  • List<LeaderBoardDriver>: List of driver information with rankings

Usage:

try {
  // Get top 10 drivers
  final topDrivers = await communicator.getLeaderboard(0, 10);
  for (final driver in topDrivers) {
    print('${driver.rank}: ${driver.name} - Score: ${driver.score}');
  }

  // Get next 10 drivers
  final nextDrivers = await communicator.getLeaderboard(10, 10);
} catch (e) {
  print('Failed to get getLeaderboard: $e');
}

Throws:

  • Future.error("Unable to get getLeaderboard details"): When retrieval fails

Use Cases:

  • Implementing paginated getLeaderboard views
  • Showing competitive rankings
  • Displaying user's position relative to others

Implementation

Future<List<LeaderBoardDriver>> getLeaderboard(int offset, int length) async {
  try {
    return await kruzr_comm.getLeaderboard(offset, length);
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
      print("PlatformException in getLeaderboard");
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
      print("Exception in getLeaderboard");
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}