fetchCasts method
Implementation
Future<List> fetchCasts([String? malId, String? kodikId]) async {
if (token == null) {
throw Exception("Token not set!");
} else {
try {
final response = await _dio.get(
'https://kodikapi.com/search?token=$token&with_episodes=true&shikimori_id=$malId');
var data = response.data;
var items = [];
for (var i = 0; i < data["results"].length; i++) {
final lastSes = data["results"][i]["last_season"];
items.add({
"name": data["results"][i]["translation"]["title"],
"kodik_id": data["results"][i]["translation"]["id"],
"episodes_count": data["results"][i]["episodes_count"],
"type": data["results"][i]["translation"]["type"],
"episodes": data["results"][i]["seasons"]["$lastSes"]["episodes"]
});
}
return items;
} on DioException catch (e) {
if (e.response!.statusCode == 500) {
throw BadDataException("Bad Data!");
} else {
throw Exception("An error has occurred");
}
}
}
}