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

Allow Overriding Curve #107

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 20 additions & 13 deletions lib/scroll_to_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,12 @@ mixin AutoScrollControllerMixin on ScrollController
duration: duration, preferPosition: preferPosition));
}

Future _scrollToIndex(int index,
{Duration duration: scrollAnimationDuration,
AutoScrollPosition? preferPosition}) async {
Future _scrollToIndex(
int index, {
Duration duration: scrollAnimationDuration,
AutoScrollPosition? preferPosition,
Curve curve = Curves.ease,
}) async {
assert(duration > Duration.zero);

// In listView init or reload case, widget state of list item may not be ready for query.
Expand Down Expand Up @@ -240,7 +243,7 @@ mixin AutoScrollControllerMixin on ScrollController

await _bringIntoViewportIfNeed(index, preferPosition,
(double offset) async {
await animateTo(offset, duration: duration, curve: Curves.ease);
await animateTo(offset, duration: duration, curve: curve);
await _waitForWidgetStateBuild();
return null;
});
Expand Down Expand Up @@ -268,12 +271,12 @@ mixin AutoScrollControllerMixin on ScrollController
prevOffset = currentOffset;
final nearest = _getNearestIndex(index);

if (tagMap[nearest ?? 0] == null)
if (tagMap[nearest ?? 0] == null)
return null;

final moveTarget =
_forecastMoveUnit(index, nearest, usedSuggestedRowHeightIfAny)!;

// assume suggestRowHeight will move to correct offset in just one time.
// if the rule doesn't work (in variable row height case), we will use backup solution (non-suggested way)
final suggestedDuration =
Expand All @@ -286,7 +289,7 @@ mixin AutoScrollControllerMixin on ScrollController
spentDuration += suggestedDuration ?? moveDuration;
final oldOffset = offset;
await animateTo(currentOffset,
duration: suggestedDuration ?? moveDuration, curve: Curves.ease);
duration: suggestedDuration ?? moveDuration, curve: curve);
await _waitForWidgetStateBuild();
if (!hasClients || offset == oldOffset) {
// already scroll to begin or end
Expand All @@ -303,9 +306,11 @@ mixin AutoScrollControllerMixin on ScrollController
if (finalOffset != offset) {
_isAutoScrolling = true;
final remaining = duration - spentDuration;
await animateTo(finalOffset,
duration: remaining <= Duration.zero ? _millisecond : remaining,
curve: Curves.ease);
await animateTo(
finalOffset,
duration: remaining <= Duration.zero ? _millisecond : remaining,
curve: curve,
);
await _waitForWidgetStateBuild();

// not sure why it doesn't scroll to the given offset, try more within 3 times
Expand All @@ -315,7 +320,7 @@ mixin AutoScrollControllerMixin on ScrollController
i < count && hasClients && offset != finalOffset;
i++) {
await animateTo(finalOffset,
duration: _millisecond, curve: Curves.ease);
duration: _millisecond, curve: curve);
await _waitForWidgetStateBuild();
}
}
Expand Down Expand Up @@ -379,7 +384,7 @@ mixin AutoScrollControllerMixin on ScrollController
} else {
final offsetToLastState =
_offsetToRevealInViewport(currentNearestIndex, alignment);

absoluteOffsetToViewport = offsetToLastState?.offset;
if (absoluteOffsetToViewport == null)
absoluteOffsetToViewport = defaultScrollDistanceOffset;
Expand Down Expand Up @@ -646,7 +651,9 @@ class AutoScrollTagState<W extends AutoScrollTag> extends State<W>
}
}

Widget buildHighlightTransition({required BuildContext context, required Animation<double> highlight,
Widget buildHighlightTransition(
{required BuildContext context,
required Animation<double> highlight,
required Widget child, Color? background, Color? highlightColor}) {
return DecoratedBoxTransition(
decoration: DecorationTween(
Expand Down