ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 10,
itemBuilder: (context, i) {
return Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Hello()
);
},
),
How can I make Hello()
only build once? I was using List.generate()
and I saw that I had to use ListView.Builder()
to make them build only once. But, it seems like it is not working. I can see that it is sending http requests as I scroll like List.generate()
.
2
Answers
You should not load the data from server in the build function, This is not the proper way.
And a private variable to hold the data:
List<String> _data = [];
Make sure you call get the data at the
initState
:Ways to show the data: