[英]ListView itemBuilder method triggered on scroll
I am using a ListView.separated with the following itemBuilder:我正在使用带有以下 itemBuilder 的ListView.separated :
itemBuilder: (context, index) {
return _buildRow(dataList[index]);
}
I noticed that this _buildRow() methods is triggered while I am scrolling.我注意到这个_buildRow()方法是在我滚动时触发的。 It seems to be triggered only the rows that are out of the screen while scrolling.
它似乎仅在滚动时触发屏幕外的行。
I do not use the setState() method within _buildRow() .我不使用_buildRow()中的setState()方法。 Also, I verified that the super method build(BuildContext context) is not triggered.
另外,我验证了超级方法build(BuildContext context)没有被触发。 It really only is the itemBuilder one.
它实际上只是 itemBuilder 之一。
I am not sure if this is a normal behavior.我不确定这是否是正常行为。 Is there a way to avoid the itemBuilder method to be re-triggered on scroll?
有没有办法避免在滚动时重新触发 itemBuilder 方法? If this is not possible, is there a way to trigger a method once the ListView build has been completed?
如果这是不可能的,有没有办法在 ListView 构建完成后触发方法?
ListView.separated
re-triggered its itemBuilder
while scrolling, as it only loads items that are shown on screen, unlike ListView which loads all the items at the time of initialization, due to this ListView
is not a good option for a long list. ListView.separated
在滚动时重新触发了它的itemBuilder
,因为它只加载显示在屏幕上的项目,不像 ListView 在初始化时加载所有项目,因为这个ListView
不是一个长列表的好选择。
This increases performance significantly when we have a long list and complex widget to render as an item of ListView.separated
.当我们有一个长列表和复杂的小部件作为
ListView.separated
的项目呈现时,这会显着提高性能。 This is the expected behavior mentioned in the question.这是问题中提到的预期行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.