Flutter GridView sliding causes ui to refresh

In Flutter, sliding a GridView does not cause a refresh by default. GridView builds subitems based on the provided data source and reuses them when scrolling to improve performance and efficiency.

When using GridView.builder or GridView.custom to build a grid view with a dynamic data source, only the children within the visible area will be built and rendered. As the user scrolls, previously constructed and rendered children are recycled and reused for new visible area children.

This mechanism makes it so that all subitems are not rebuilt and refreshed during scrolling, but only existing subitems are reused. This can effectively improve scrolling performance and reduce resource consumption.

If you want to trigger refresh behavior during scrolling, you can manually call the setState() method in the scroll event listener to update the state and rebuild the GridView . In this way, the refresh effect when scrolling can be achieved.

To sum up, GridView 's sliding will not refresh by default, but you can manually update the state and rebuild to achieve the refresh behavior when scrolling.

おすすめ

転載: blog.csdn.net/qq_27981847/article/details/131725395