简体   繁体   English

滚动时触发的 ListView itemBuilder 方法

[英]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.

相关问题 TextStyle不适用于ListView itemBuilder - TextStyle not applied to ListView itemBuilder ListView.builder itemBuilder function 在创建列表后在滚动时重新执行 - ListView.builder itemBuilder function re-executes on scroll after list is created 如何使列表视图与 itemBuilder 一起使用 - How to make listview to work with itemBuilder 错误:ListView.builder 的 itemCount 和 itemBuilder 参数无效 - Error: itemCount and itemBuilder invalid arguments for ListView.builder Flutter ListView itembuilder 不会显示任何内容。 为什么? - Flutter ListView itembuilder won't show anything. Why? Flutter:基于网络图像尺寸的不同ListView ItemBuilder 布局 - Flutter: Different ListView ItemBuilder layouts based on Network image dimensions 是否可以在不使用 itembuilder 的情况下使用 Listview.seperated? - Is it possible to have a Listview.seperated without having to use a itembuilder? flutter/ 当你在listview的itemBuilder中使用Align时,最后一个小部件消失了 - flutter/ The last widget disappears when you use Align in the itemBuilder in listview 如何在 listview.seperated 中的 itemBuilder 之前构建 seperatorBuilder - How to build seperatorBuilder before itemBuilder in listview.seperated 问:使用 ListView.builder 并显示“ListView.builder(itemBuilder: null)” - Q: Using ListView.builder and it showed "ListView.builder(itemBuilder: null)"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM