Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use PositionRetainedScrollPhysics #7

Merged
merged 1 commit into from
Mar 19, 2023
Merged

use PositionRetainedScrollPhysics #7

merged 1 commit into from
Mar 19, 2023

Conversation

SimonWang9610
Copy link
Owner

Problem:

  • using RetainableScrollController may break developers' existing code implementations
  • and developers have to invoke RetaibleScrollController.retainOffset() explicitly to achieve their goals.

Solution:
By deprecating RetainableScrollController, we could use PositionRetainedScrollPhysics to achieve the same goals, but without introducing breakage into your existing projects. The usage is like below:

ListView.builder(
  controller: _controller,
  reverse: true,
  physics: const PositionRetainedScrollPhysics(),
  itemBuilder: (context, index) => _items[index],
  itemCount: _itemCount,
);

The only thing would change is passing physics: const PositionRetainedScrollPhysics() in your ListView. Particularly, you could also disable retaining the scroll position by setting PositionRetainedScrollPhysics.shouldRetain = false. Besides, it could also be applyTo other ScrollPhysics.

@SimonWang9610 SimonWang9610 merged commit 2d0b251 into main Mar 19, 2023
@SimonWang9610 SimonWang9610 deleted the keep-offset branch October 16, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant