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: () {
},
)
),
);
}
);
}
);
}
}