I am using FutureProvider to fetch data(places) from Laravel API to show that data in flutter. Now the problem is it is rebuilding again and again that even server started throwing error of "too many attempts". I am using ListView.builder to show all places fetch from API but when I scroll to next places and then scroll back to previous it rebuilds. Mean FutureProvider is rebuilding again and again. Here is code attached. I also tried to add addAutomaticKeepAlives: true, in ListView to save the state
Container(
height: 100,
child: ListView.builder(
addAutomaticKeepAlives: true,
scrollDirection: Axis.horizontal,
itemCount: places.length,
itemBuilder: (_, index) {
return FutureProvider(
initialData: null,
create: (context) =>
getFireIceCount(index, places),
child: Consumer<List<dynamic>>(
builder: (context, fireIceCount,
child) {
return (fireIceCount != null)
? (fireIceCount.isNotEmpty)
? PlacesImageViewer()
: Center(
child:
CircularProgressIndicator(
color:
Colors.cyan,
),
)
: Center(
child:
CircularProgressIndicator(
color: Colors.red,
),
);
},
),
);
},
),
),