fetchAvailableRewards method
Retrieves all rewards available in the Kruzr rewards catalog.
Fetches the complete list of rewards that users can claim using their accumulated points from driving achievements and performance. Each reward includes details about point cost, description, and redemption information.
Returns:
List<AvailableReward>: List of all available rewards in the catalog
Usage:
try {
final availableRewards = await fetchAvailableRewards();
for (final reward in availableRewards) {
print('Reward: ${reward.title}');
print('Description: ${reward.description}');
print('Cost: ${reward.points} points');
print('Code: ${reward.rewardCode}');
print('---');
}
// Filter rewards by point cost
final affordableRewards = availableRewards.where((reward) =>
reward.points != null && reward.points! <= userCurrentPoints
).toList();
} catch (e) {
print('Failed to fetch available rewards: $e');
}
Throws:
Future.error("Unable to fetch available rewards"): When retrieval fails
Reward Information Includes:
- ID: Unique identifier for the reward
- Title: Display name (e.g., "Free Coffee Voucher", "5% Gas Discount")
- Description: Detailed information about the reward benefits
- Points: Cost in points required to redeem the reward
- Reward Code: Unique code for redemption tracking
Use Cases:
- Rewards catalog display
- Point-based filtering and sorting
- Redemption interface
- User motivation and engagement
- Loyalty program management
Prerequisites:
- User must be logged in
- Active internet connection required
- Rewards system must be enabled for the account
Implementation
Future<List<AvailableReward>> fetchAvailableRewards() async {
try {
return await kruzr_comm.fetchAvailableRewards();
} on Exception catch (e, stackTrace) {
if (kDebugMode) {
print("Error in fetchAvailableRewards");
print(stackTrace);
print(e);
}
return Future.error("Unable to fetch available rewards");
}
}