@@ -631,7 +631,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
631631 @override
632632 void didUpdateWidget (covariant DraggableScrollableSheet oldWidget) {
633633 super .didUpdateWidget (oldWidget);
634- _replaceExtent ();
634+ _replaceExtent (oldWidget );
635635 }
636636
637637 @override
@@ -671,7 +671,7 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
671671 super .dispose ();
672672 }
673673
674- void _replaceExtent () {
674+ void _replaceExtent (covariant DraggableScrollableSheet oldWidget ) {
675675 final _DraggableSheetExtent previousExtent = _extent;
676676 _extent.dispose ();
677677 _extent = _extent.copyWith (
@@ -688,13 +688,21 @@ class _DraggableScrollableSheetState extends State<DraggableScrollableSheet> {
688688 // If an external facing controller was provided, let it know that the
689689 // extent has been replaced.
690690 widget.controller? ._onExtentReplaced (previousExtent);
691- if (widget.snap) {
692- // Trigger a snap in case snap or snapSizes has changed. We put this in a
693- // post frame callback so that `build` can update `_extent.availablePixels`
694- // before this runs-we can't use the previous extent's available pixels as
695- // it may have changed when the widget was updated.
691+ if (widget.snap
692+ && (widget.snap != oldWidget.snap || widget.snapSizes != oldWidget.snapSizes)
693+ && _scrollController.hasClients
694+ ) {
695+ // Trigger a snap in case snap or snapSizes has changed and there is a
696+ // scroll position currently attached. We put this in a post frame
697+ // callback so that `build` can update `_extent.availablePixels` before
698+ // this runs-we can't use the previous extent's available pixels as it may
699+ // have changed when the widget was updated.
696700 WidgetsBinding .instance.addPostFrameCallback ((Duration timeStamp) {
697- _scrollController.position.goBallistic (0 );
701+ for (int index = 0 ; index < _scrollController.positions.length; index++ ) {
702+ final _DraggableScrollableSheetScrollPosition position =
703+ _scrollController.positions.elementAt (index) as _DraggableScrollableSheetScrollPosition ;
704+ position.goBallistic (0 );
705+ }
698706 });
699707 }
700708 }
0 commit comments