directory

  1. Create a nested slide PageView with Flutter from scratch
  2. Create a nested slide PageView with Flutter from scratch
  3. Create a nested slide PageView with Flutter from scratch

preface

The first two articles have basically achieved the required functions, so the comprehensive integration, and do some slight expansion

Thinking to integrate

1. The general idea

The bottom child PageView is responsible for calculation, under normal circumstances according to the general logic of PageView, when the need to nest sliding, calculate the sliding result and call the controller of the parent Page.

So by this logic, the bottom scrollerController is the core of the operation, where the computation logic and all that goes on, and then you control the parent page when you need to, okay

2. Calculate the core logic

Normal situation directly reference pageView on the line, we only need to consider the nested sliding situation, this part of the reference to nestedScrollerView part, is to judge whether it is excessive sliding, fast sliding what, To the parent ScrollerController if necessary. Fortunately, the basic animation and reset algorithms have been implemented in a ready way, and excessive sliding can also be determined by the pixel, maxScrollExtent, minScrollExtent and other information carried in the position bound to the controller, so there is no problem

3, how to get through the parent page and child page

Or reference NestedScrollerView PrimaryScrollerController provides a way to transfer the controller, So the parent Page only need to put their own controller in PrimaryScrollerController this InHeritedWidget, sub Page by it can get the controller, which controlled the parent Page of sliding.

What needs to be done

1. Modify the pageView, make its have PrimaryScroolerController 2. Customize ScrollerController to provide position and related necessary information 3. Create a custom ScrollerPosition that inherits ScrollActivityDelegate, custom activity and control logic, and add computing core logic

I can extend it a little bit

Doll function, now is currently the parent page and child page is separate, but think about it, the parent page actually provides its own controller a very small function, can be integrated into the child page, Directly with a pageView automatic judgment need nested function well (ie, through PrimaryScrollerController can get the parent page under a custom ScrollerController line)

2020.3.16 Updated, the above functions have been added

Information that can now be made public

  1. Unlimited nesting is supported

  2. You can set the display index of the initial pageView of a nested page

Basic effect Look

The basic function

The project address

Use demo see comment 1

https://gist.github.com/lwlizhe/558ee91b691a7d9e6873f16d9abccf78

Afterword.

Who would have thought the Spring Festival holiday would be so long… Come back person silly, almost can’t recognize what I write before ………… Get your head in the right place

By the way, I want to change my status.

As it turns out, some things can be pretty forgettable without coding for a month…