1

I don't know how it's possible for snapshot.data can be null as I initialized it with an element to prevent any empty list (even though empty lists are not null objects). I think the issue is in the _searchChapter function since on another screen the same length works. Hope you can help and thank in advance.

class Chapters_detail extends StatelessWidget {
const Chapters_detail({Key key, @required this.manga,}) : super(key: key);

final Manga manga;


Future<List<MangaChapter>> _searchChapter (Manga manga) async {
  String manga_id = manga.id;
  var response = await http.get(Uri.parse('https://api.mangadex.org/manga/$manga_id/feed?limit=500&locales[]=en'));
  var data0 = jsonDecode(response.body);
  MangaChapter test = MangaChapter(id: '1', chapter: '123', hash: '12');
  List<MangaChapter> chapitres = [test];
  for (var result in data0['results']){
    MangaChapter temp = MangaChapter (
      id: result['data']['id'],
      chapter: result['data']['attributes']['chapter'],
      hash: result['data']['attributes']['hash'],
      data: result['data']['attributes']['data'],
      dataSaver: result['data']['attributes']['dataSaver'],
    );
    chapitres.add(temp);
  }
  return chapitres;

}


Widget build(BuildContext context) {
  return FutureBuilder(
    future: _searchChapter(manga),
    builder: (BuildContext context, AsyncSnapshot snapshot){

      return ListView.builder(
        itemCount: snapshot.data.length,
        itemBuilder: (BuildContext context, int index){
          return Column(
            children: List.generate(
                snapshot.data.length,
                    (index) => ListTile(
                  title: Text(snapshot.data[index].chapter),
                  leading: Icon(Icons.phone_android),
                  onTap: () {
                  },
                )
            ),
          );
        }
      );
    }
  );
}
}

  • 1
    Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt May 20 '21 at 13:09
  • You are running your FutureBuilder code, regardless of whether your future is done yet. You need to make sure you handle the cases where it's not. See – nvoigt May 20 '21 at 13:11
  • Thanks a lot nvoigt, that was it !!! – whydoesitneverwork0 May 20 '21 at 13:22

0 Answers0