Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions lib/src/animate_to_item.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dart:async";
import "dart:ui";

import "package:flutter/widgets.dart";
Expand All @@ -13,7 +14,7 @@ class AnimateToItem {
required this.position,
required this.duration,
required this.curve,
});
}) : _completer = Completer<void>();

final ExtentManager extentManager;
final ValueGetter<int?> index;
Expand All @@ -22,13 +23,15 @@ class AnimateToItem {
final ScrollPosition position;
final Duration Function(double estimatedDistance) duration;
final Curve Function(double estimatedDistance) curve;

final Completer<void> _completer;

double lastPosition = 0.0;

void animate() {
Future<void> animate() {
final index = this.index();
if (index == null) {
return;
return Future<void>.value();
}
final start = position.pixels;
final estimatedTarget = extentManager.getOffsetToReveal(
Expand All @@ -44,6 +47,7 @@ class AnimateToItem {
);
controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
_completer.complete();
controller.dispose();
}
});
Expand All @@ -56,6 +60,7 @@ class AnimateToItem {
final index = this.index();
if (index == null) {
controller.stop();
_completer.complete();
controller.dispose();
return;
}
Expand Down Expand Up @@ -84,5 +89,6 @@ class AnimateToItem {
position.jumpTo(jumpPosition);
});
controller.forward();
return _completer.future;
}
}
25 changes: 13 additions & 12 deletions lib/src/super_sliver_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ListController extends ChangeNotifier {
/// edge of the viewport. If the value is 0.5, the item will be positioned in
/// the middle of the viewport. If the value is 1.0, the item will be
/// positioned at the trailing edge of the viewport.
void animateToItem({
Future<void> animateToItem({
required ValueGetter<int?> index,
required ScrollController scrollController,
required double alignment,
Expand All @@ -133,17 +133,18 @@ class ListController extends ChangeNotifier {
Rect? rect,
}) {
assert(_delegate != null, "ListController is not attached.");
for (final position in scrollController.positions) {
AnimateToItem(
extentManager: _delegate!,
index: index,
alignment: alignment,
rect: rect,
position: position,
curve: curve,
duration: duration,
).animate();
}
return Future.wait([
for (final position in scrollController.positions)
AnimateToItem(
extentManager: _delegate!,
index: index,
alignment: alignment,
rect: rect,
position: position,
curve: curve,
duration: duration,
).animate()
]);
}

/// Returns the range of items indices currently visible in the viewport.
Expand Down