getUserRank method

Future<UserRank?> getUserRank()

Retrieves the current user's rank in the getLeaderboard 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, or null if not available

Usage:

try {
  final rank = await communicator.getUserRank();
  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?> getUserRank() async {
  try {
    return await kruzr_comm.getUserRank();
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
      print("PlatformException in getUserRank");
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
      print("Exception in getUserRank");
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}