getCurrentUserRank method
Retrieves the current user's rank in the leaderboard system.
The rank is calculated based on driving performance metrics and compares the user against other drivers in the same company/group.
Returns:
UserRank?: Rank information object, ornullif not available
Usage:
try {
final rank = await communicator.getCurrentUserRank();
if (rank != null) {
print('Current rank: ${rank.currentRank}');
print('Total participants: ${rank.totalParticipants}');
}
} catch (e) {
print('Failed to get user rank: $e');
}
Throws:
Future.error("Unable to get user rank"): When retrieval fails
Prerequisites:
- User must be logged in
- Sufficient trip data for meaningful ranking
Implementation
Future<UserRank?> getCurrentUserRank() async {
try {
return await kruzr_comm.getCurrentUserRank();
} on PlatformException catch (e) {
if (kDebugMode) {
print(e);
print("PlatformException in getCurrentUserRank");
}
return Future.error("Unable to get user rank");
} on Exception catch (e) {
if (kDebugMode) {
print(e);
print("Exception in getCurrentUserRank");
}
return Future.error("Unable to get current user rank");
}
}