getMangaInfo method Null safety
Gets information about manga
If appendChapters
is true
, returns available chapters in .chapters
If there are no chapters available or appendChapters
is false
, .chapters
returns an empty Map
If appending chapters, translatedLang
should be either an empty Array (which will append chapters of all languages) or filled with codes of desired languages
Returns Null if no manga can be found
Implementation
Future<Manga?> getMangaInfo(String uuid,
{bool appendChapters = false,
List<String> translatedLang = const []}) async {
var res;
if (token != '') {
res = await http.get(Uri.parse('https://api.mangadex.org/manga/$uuid'),
headers: {HttpHeaders.authorizationHeader: 'Bearer $token'});
} else {
res = await http.get(Uri.parse('https://api.mangadex.org/manga/$uuid'));
}
var data = jsonDecode(res.body)['data'];
// ignore: omit_local_variable_types
Map<String, dynamic> chapters = {};
// append available chapters from other API endpoint
if (appendChapters) {
var chres = await http
.get(Uri.parse('https://api.mangadex.org/manga/$uuid/aggregate'));
chapters = Map.from(jsonDecode(chres.body)['volumes']);
}
var covers = await getCovers(uuid);
var manga = Manga(
altTitles: data['attributes']['altTitles'],
title: Map.from(data['attributes']['title']),
tags: data['attributes']['tags'],
description: Map.from(data['attributes']['description']),
isLocked: data['attributes']['isLocked'],
links: (data['attributes']['links'] == null)
? null
: Map.from(data['attributes']['links']),
originalLang: data['attributes']['originalLanguage'],
lastChapter: data['attributes']['lastChapter'],
lastVolume: data['attributes']['lastVolume'],
demographic: data['attributes']['publicationDemographic'],
status: data['attributes']['status'],
releaseYear: data['attributes']['year'],
contentRating: data['attributes']['contentRating'],
createdAt: data['attributes']['createdAt'],
updatedAt: data['attributes']['updatedAt'],
id: data['id'],
chapters: chapters,
covers: covers!);
return manga;
}