Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Products',
),
),
body: Center(
child: FutureBuilder(
future: fetchPhotos(),
builder: (ctx, snapShot) {
if (snapShot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else {
return ListView.builder(
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
backgroundColor: Colors.red,
),
title: Text(snapShot.data["table"][index]["name"]),
subtitle: Text(
"price: ${snapShot.data["table"][index]["class_id"]}"),
);
},
);
}
},
),
),
);
}
What should I put in it itemCount so as not to show an error : Exception caught by widgets library RangeError (index): Invalid value: Not in inclusive range 0..35: 36
Add the itemCount
parameter to yout listView Builder as :
ListView.builder(
itemCount: snapShot.data["table"].length,
itemBuilder: (context, index) {
...
This way flutter knows when to stop building items