getCovers method Null safety
Gets 10
of available cover images for a manga
Requires valid manga UUID
Returns Null if no found
Implementation
Future<List<String>?> getCovers(String mangaUuid,
{bool useLogin = false}) async {
var res;
if (token != '' && useLogin) {
res = await http.get(
Uri.parse('https://api.mangadex.org/cover?manga[]=$mangaUuid'),
headers: {
HttpHeaders.authorizationHeader: 'Bearer $token',
HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'
});
} else {
res = await http.get(
Uri.parse('https://api.mangadex.org/cover?manga[]=$mangaUuid'),
headers: {HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'});
}
if (res.statusCode == 404) {
return null;
}
var data = jsonDecode(res.body)['results'];
if (res.statusCode == 403 && res.headers['X-Captcha-Sitekey'] != null) {
throw CaptchaException(res.headers['X-Captcha-Sitekey'],
message:
'You need to solve a captcha, check `.sitekey` for the sitekey.');
}
// ignore: omit_local_variable_types
List<String> covers = [];
for (var item in data) {
covers.add(
'https://uploads.mangadex.org/covers/$mangaUuid/${item["data"]["attributes"]["fileName"]}');
}
return covers;
}