search method

Future<List> search(
  1. String searchQuery
)

Implementation

Future<List> search(String searchQuery) async {
  // get request with the given query
  final res = await http.Client().get(Uri.parse('$SEARCH_URL$searchQuery'));
  if (res.statusCode == 200) {
    // get the body and look for the animes found
    final body = res.body.toString();
    final soup = BeautifulSoup(body);
    final elements = soup.findAll('article', class_: 'Anime alt B');
    var ret = [];
    // for each of the animes found we'll save some data
    for (var element in elements) {
      var id =
          element.find('', selector: 'div.Description a.Button')?['href'];
      try {
        ret.add({
          'id': id?.substring(1, id.length),
          'title': element.find('', selector: 'a h3')?.string,
          'poster': element.find('', selector: '.Image figure img')?['src'],
          'banner': element
              .find('', selector: '.Image figure img')?['src']
              ?.replaceAll('covers', 'banners')
              .trim(),
          'type': element
              .find('', selector: 'div.Description p span.Type')
              ?.string,
          'synopsis': element
              .findAll('', selector: 'div.Description p')[1]
              .string
              .trim(),
          'rating': element
              .find('', selector: 'div.Description p span.Vts')
              ?.string,
        });
      } catch (e) {}
    }
    // return the list of animes found
    return ret;
  }
  return [];
}