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

Attach Scroll listener to secondary list navigated to an item at long… #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
widget.scrollOffsetController?._attach(this);
primary.itemPositionsNotifier.itemPositions.addListener(_updatePositions);
secondary.itemPositionsNotifier.itemPositions.addListener(_updatePositions);
primary.scrollController.addListener(() {
final currentOffset = primary.scrollController.offset;
final offsetChange = currentOffset - previousOffset;
previousOffset = currentOffset;
if (!_isTransitioning |
(widget.scrollOffsetNotifier?.recordProgrammaticScrolls ?? false)) {
widget.scrollOffsetNotifier?.changeController.add(offsetChange);
}
});
primary.scrollController.addListener(_scrollListener);
}

@override
Expand All @@ -369,6 +361,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
.removeListener(_updatePositions);
secondary.itemPositionsNotifier.itemPositions
.removeListener(_updatePositions);
primary.scrollController.removeListener(_scrollListener);
_animationController?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -612,9 +605,11 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
if (opacity.value >= 0.5) {
// Secondary [ListView] is more visible than the primary; make it the
// new primary.
primary.scrollController.removeListener(_scrollListener);
var temp = primary;
primary = secondary;
secondary = temp;
primary.scrollController.addListener(_scrollListener);
}
_isTransitioning = false;
opacity.parent = const AlwaysStoppedAnimation<double>(0);
Expand Down Expand Up @@ -652,6 +647,16 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
}
widget.itemPositionsNotifier?.itemPositions.value = itemPositions;
}

void _scrollListener() {
final currentOffset = primary.scrollController.offset;
final offsetChange = currentOffset - previousOffset;
previousOffset = currentOffset;
if (!_isTransitioning |
(widget.scrollOffsetNotifier?.recordProgrammaticScrolls ?? false)) {
widget.scrollOffsetNotifier?.changeController.add(offsetChange);
}
}
}

class _ListDisplayDetails {
Expand Down