@@ -795,8 +795,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
795
795
/// See also:
796
796
///
797
797
/// * [_DraggableScrollableSheetScrollController] , which uses this as its [ScrollPosition] .
798
- class _DraggableScrollableSheetScrollPosition
799
- extends ScrollPositionWithSingleContext {
798
+ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleContext {
800
799
_DraggableScrollableSheetScrollPosition ({
801
800
required super .physics,
802
801
required super .context,
@@ -805,16 +804,18 @@ class _DraggableScrollableSheetScrollPosition
805
804
});
806
805
807
806
VoidCallback ? _dragCancelCallback;
808
- VoidCallback ? _ballisticCancelCallback;
809
807
final _DraggableSheetExtent Function () getExtent;
808
+ final Set <AnimationController > _ballisticControllers = < AnimationController > {};
810
809
bool get listShouldScroll => pixels > 0.0 ;
811
810
812
811
_DraggableSheetExtent get extent => getExtent ();
813
812
814
813
@override
815
814
void beginActivity (ScrollActivity ? newActivity) {
816
- // Cancel the running ballistic simulation, if there is one.
817
- _ballisticCancelCallback? .call ();
815
+ // Cancel the running ballistic simulations
816
+ for (final AnimationController ballisticController in _ballisticControllers) {
817
+ ballisticController.stop ();
818
+ }
818
819
super .beginActivity (newActivity);
819
820
}
820
821
@@ -852,8 +853,10 @@ class _DraggableScrollableSheetScrollPosition
852
853
853
854
@override
854
855
void dispose () {
855
- // Stop the animation before dispose.
856
- _ballisticCancelCallback? .call ();
856
+ for (final AnimationController ballisticController in _ballisticControllers) {
857
+ ballisticController.dispose ();
858
+ }
859
+ _ballisticControllers.clear ();
857
860
super .dispose ();
858
861
}
859
862
@@ -873,10 +876,11 @@ class _DraggableScrollableSheetScrollPosition
873
876
if (extent.snap) {
874
877
// Snap is enabled, simulate snapping instead of clamping scroll.
875
878
simulation = _SnappingSimulation (
876
- position: extent.currentPixels,
877
- initialVelocity: velocity,
878
- pixelSnapSize: extent.pixelSnapSizes,
879
- tolerance: physics.tolerance);
879
+ position: extent.currentPixels,
880
+ initialVelocity: velocity,
881
+ pixelSnapSize: extent.pixelSnapSizes,
882
+ tolerance: physics.tolerance,
883
+ );
880
884
} else {
881
885
// The iOS bouncing simulation just isn't right here - once we delegate
882
886
// the ballistic back to the ScrollView, it will use the right simulation.
@@ -892,9 +896,8 @@ class _DraggableScrollableSheetScrollPosition
892
896
debugLabel: objectRuntimeType (this , '_DraggableScrollableSheetPosition' ),
893
897
vsync: context.vsync,
894
898
);
895
- // Stop the ballistic animation if a new activity starts.
896
- // See: [beginActivity].
897
- _ballisticCancelCallback = ballisticController.stop;
899
+ _ballisticControllers.add (ballisticController);
900
+
898
901
double lastPosition = extent.currentPixels;
899
902
void tick () {
900
903
final double delta = ballisticController.value - lastPosition;
@@ -916,8 +919,10 @@ class _DraggableScrollableSheetScrollPosition
916
919
..addListener (tick)
917
920
..animateWith (simulation).whenCompleteOrCancel (
918
921
() {
919
- _ballisticCancelCallback = null ;
920
- ballisticController.dispose ();
922
+ if (_ballisticControllers.contains (ballisticController)) {
923
+ _ballisticControllers.remove (ballisticController);
924
+ ballisticController.dispose ();
925
+ }
921
926
},
922
927
);
923
928
}
0 commit comments