Flutter component - ListView slides to the specified position (SingleChildScrollView realizes the anchor point effect)

1. Introduction to SingleChildScrollView:

The ListView component has a lazy loading feature when it has a lot of default content. 

SingleChildScrollView does not support the lazy instantiation model based on Sliver, which is to use SingleChildScrollView 

By default there is no lazy loading feature. 

SingleChildScrollView is similar to ScrollView in Android, it can only receive one child component, since there is no 

It has the feature of lazy loading, so we can get the positions of all the speeds in it at the beginning, so that we can implement it well 

Now the anchor point effect.

2. Implementation process of SingleChildScrollView anchor point:

Wrap all the code that needs anchors with SingleChildScrollView, create a corresponding GlobalKey for each anchor, 

Use Scrollable's ensureVisible method to jump to each key.

Step 1: Create a key

GlobalKey gk1 = GlobalKey();

Step 2: Change the listView (or Container) of the layout to SingleChildScrollView

Step 3: Realize the jump

Scrollable.ensureVisible(gk1.currentContext as BuildContext)

Guess you like

Origin blog.csdn.net/eastWind1101/article/details/131366048