leaderboard method
Retrieves a paginated list of drivers from the leaderboard.
The leaderboard ranks drivers based on their driving performance metrics within the same company/account group.
Parameters:
offset: Starting position in the leaderboard (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.leaderboard(0, 10);
for (final driver in topDrivers) {
print('${driver.rank}: ${driver.name} - Score: ${driver.score}');
}
// Get next 10 drivers
final nextDrivers = await communicator.leaderboard(10, 10);
} catch (e) {
print('Failed to get leaderboard: $e');
}
Throws:
Future.error("Unable to get leaderboard details"): When retrieval fails
Use Cases:
- Implementing paginated leaderboard views
- Showing competitive rankings
- Displaying user's position relative to others
Implementation
Future<List<LeaderBoardDriver>> leaderboard(int offset, int length) async {
try {
return await kruzr_comm.leaderBoard(offset, length);
} on PlatformException catch (e) {
if (kDebugMode) {
print(e);
print("PlatformException in leaderboard");
}
return Future.error("Unable to get leaderboard details");
} on Exception catch (e) {
if (kDebugMode) {
print(e);
print("Exception in leaderboard");
}
return Future.error("Unable to get leaderboard details");
}
}