@@ -15,6 +15,7 @@ library;
15
15
16
16
import 'dart:math' as math;
17
17
18
+ import 'package:collection/collection.dart' ;
18
19
import 'package:flutter/foundation.dart' ;
19
20
import 'package:flutter/gestures.dart' ;
20
21
@@ -909,14 +910,18 @@ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleCo
909
910
}
910
911
}
911
912
912
- bool get _isAtSnapSize {
913
- return extent.snapSizes.any ((double snapSize) {
913
+ // Checks if the sheet's current size is close to a snap size, returning the
914
+ // snap size if so; returns null otherwise.
915
+ double ? _getCurrentSnapSize () {
916
+ return extent.snapSizes.firstWhereOrNull ((double snapSize) {
914
917
return (extent.currentSize - snapSize).abs () <=
915
918
extent.pixelsToSize (physics.toleranceFor (this ).distance);
916
919
});
917
920
}
918
921
919
- bool get _shouldSnap => extent.snap && extent.hasDragged && ! _isAtSnapSize;
922
+ bool _isAtSnapSize () => _getCurrentSnapSize () != null ;
923
+
924
+ bool _shouldSnap () => extent.snap && extent.hasDragged && ! _isAtSnapSize ();
920
925
921
926
@override
922
927
void dispose () {
@@ -929,7 +934,7 @@ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleCo
929
934
930
935
@override
931
936
void goBallistic (double velocity) {
932
- if ((velocity == 0.0 && ! _shouldSnap) ||
937
+ if ((velocity == 0.0 && ! _shouldSnap () ) ||
933
938
(velocity < 0.0 && listShouldScroll) ||
934
939
(velocity > 0.0 && extent.isAtMax)) {
935
940
super .goBallistic (velocity);
@@ -981,6 +986,13 @@ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleCo
981
986
super .goBallistic (velocity);
982
987
ballisticController.stop ();
983
988
} else if (ballisticController.isCompleted) {
989
+ // Update the extent value after the snap animation completes to
990
+ // avoid rounding errors that could prevent the sheet from closing when
991
+ // it reaches minSize.
992
+ final double ? snapSize = _getCurrentSnapSize ();
993
+ if (snapSize != null ) {
994
+ extent.updateSize (snapSize, context.notificationContext! );
995
+ }
984
996
super .goBallistic (0 );
985
997
}
986
998
}
0 commit comments