fetchUserProfileTierRequirements method

Future<List<UserProfileTierRequirement>> fetchUserProfileTierRequirements()

Retrieves all available user profile tiers along with their eligibility requirements.

Fetches metadata describing each profile tier that a user can achieve through driving behavior. Each tier includes information such as the tier name, description, minimum number of trips, and minimum average score required to unlock it.

This data is typically used to display tier progression, locked tiers, and next-level goals within the application UI.

Returns:

  • List<UserProfileTierRequirement>: A list of profile tier requirement objects describing all available tiers.

Usage:

try {
  final tierRequirements = await fetchUserProfileTierRequirements();

  if (tierRequirements.isNotEmpty) {
    for (final tier in tierRequirements) {
      print('Tier: ${tier.name}');
      print('Description: ${tier.description}');
      print('Required trips: ${tier.requiredTrips}');
      print('Required score: ${tier.requiredScore}');
      print('Tier enum: ${tier.tier}');
      print('---');
    }

    // Example: Find the highest available tier
    final highestTier = tierRequirements
        .reduce((a, b) => a.grade > b.grade ? a : b);
    print('Highest tier: ${highestTier.name}');
  } else {
    print('No profile tiers available.');
  }
} catch (e) {
  print('Failed to fetch profile tier requirements: $e');
}

Throws:

  • Future.error("Unable to fetch profile tier requirements"): When the request fails due to a network issue or server error.

Profile Tier Requirement Information Includes:

  • Grade: Ordering value used to rank tiers from lowest to highest
  • Name: Display name of the tier
  • Description: Explanation of the tier and how to unlock it
  • Tier: Enum identifier representing the profile tier
  • Required Trips: Minimum number of trips needed to unlock the tier
  • Required Score: Minimum average score needed to unlock the tier

Use Cases:

  • Profile progression UI
  • Locked tier explanation screens
  • User motivation and goal-setting
  • Gamification and engagement features
  • Tier comparison and ranking displays

Prerequisites:

  • User must be logged in
  • Active internet connection required

Implementation

Future<List<UserProfileTierRequirement>>
fetchUserProfileTierRequirements() async {
  try {
    return await kruzr_comm.fetchUserProfileTierRequirements();
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in fetchUserProfileTierRequirements");
      print(stackTrace);
      print(e);
    }
    return Future.error("Unable to fetch profile tier requirements");
  }
}