fetchUserBadges function
Implementation
Future<List<String>> fetchUserBadges(
String playerUid, PlayMode playMode, Config config) async {
String path = config.server +
'/api/tenant/${config.operatorId}/user-badges?filter[application]=${config.application}&filter[player_uid]=$playerUid&filter[category]=${config.category}&filter[playMode]=${playMode.toString()}';
final response = await http.get(Uri.parse(path), headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ${config.token}',
});
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
var rb = response.body;
// store json data into list
var badgesResponse = json.decode(rb) as List<String>;
return badgesResponse;
} else {
throw Exception('Failed to load user badges');
}
}