searchWorks method Null safety
- String nameOfWork
searchWorks searches the first page of results for the query in the argument.
If a work has multiple fandoms, only the first is listed.
If the webscraping does not work for any of the String fields in the work class, "Unknown" will be placed instead.
If the number of chapters or workID can't be found, 1 will be placed instead. This is primarily because OneShots don't work the sameway in the chapter count department.
Implementation
static Future<List<Work>> searchWorks(final String nameOfWork) async {
final worksFound = <Work>[];
final resp = await http.get(Uri.parse(
"https://archiveofourown.org/works/search?work_search%5Bquery%5D=$nameOfWork"));
if (resp.statusCode == 404) {
throw ("Error 404");
}
final works = parse(resp.body).querySelectorAll("li.work");
for (final work in works) {
worksFound.add(_getWork(work));
}
return worksFound;
}