@@ -52,6 +52,7 @@ typedef ScrollableWidgetBuilder = Widget Function(
52
52
/// constraints provided to an attached sheet change.
53
53
class DraggableScrollableController extends ChangeNotifier {
54
54
_DraggableScrollableSheetScrollController ? _attachedController;
55
+ final Set <AnimationController > _animationControllers = < AnimationController > {};
55
56
56
57
/// Get the current size (as a fraction of the parent height) of the attached sheet.
57
58
double get size {
@@ -115,6 +116,7 @@ class DraggableScrollableController extends ChangeNotifier {
115
116
vsync: _attachedController! .position.context.vsync,
116
117
value: _attachedController! .extent.currentSize,
117
118
);
119
+ _animationControllers.add (animationController);
118
120
_attachedController! .position.goIdle ();
119
121
// This disables any snapping until the next user interaction with the sheet.
120
122
_attachedController! .extent.hasDragged = false ;
@@ -175,6 +177,7 @@ class DraggableScrollableController extends ChangeNotifier {
175
177
assert (_attachedController == null , 'Draggable scrollable controller is already attached to a sheet.' );
176
178
_attachedController = scrollController;
177
179
_attachedController! .extent._currentSize.addListener (notifyListeners);
180
+ _attachedController! .onPositionDetached = _disposeAnimationControllers;
178
181
}
179
182
180
183
void _onExtentReplaced (_DraggableSheetExtent previousExtent) {
@@ -193,6 +196,13 @@ class DraggableScrollableController extends ChangeNotifier {
193
196
_attachedController? .extent._currentSize.removeListener (notifyListeners);
194
197
_attachedController = null ;
195
198
}
199
+
200
+ void _disposeAnimationControllers () {
201
+ for (final AnimationController animationController in _animationControllers) {
202
+ animationController.dispose ();
203
+ }
204
+ _animationControllers.clear ();
205
+ }
196
206
}
197
207
198
208
/// A container for a [Scrollable] that responds to drag gestures by resizing
@@ -724,6 +734,7 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
724
734
}) : assert (extent != null );
725
735
726
736
_DraggableSheetExtent extent;
737
+ VoidCallback ? onPositionDetached;
727
738
728
739
@override
729
740
_DraggableScrollableSheetScrollPosition createScrollPosition (
@@ -764,6 +775,12 @@ class _DraggableScrollableSheetScrollController extends ScrollController {
764
775
}
765
776
extent.updateSize (extent.initialSize, position.context.notificationContext! );
766
777
}
778
+
779
+ @override
780
+ void detach (ScrollPosition position) {
781
+ onPositionDetached? .call ();
782
+ super .detach (position);
783
+ }
767
784
}
768
785
769
786
/// A scroll position that manages scroll activities for
0 commit comments