Showing
1 changed file
with
19 additions
and
16 deletions
@@ -45,7 +45,7 @@ class ModalBottomSheet extends StatefulWidget { | @@ -45,7 +45,7 @@ class ModalBottomSheet extends StatefulWidget { | ||
45 | required this.expanded, | 45 | required this.expanded, |
46 | required this.onClosing, | 46 | required this.onClosing, |
47 | required this.child, | 47 | required this.child, |
48 | - }) : super(key: key); | 48 | + }) : super(key: key); |
49 | 49 | ||
50 | /// The closeProgressThreshold parameter | 50 | /// The closeProgressThreshold parameter |
51 | /// specifies when the bottom sheet will be dismissed when user drags it. | 51 | /// specifies when the bottom sheet will be dismissed when user drags it. |
@@ -224,24 +224,27 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -224,24 +224,27 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
224 | // ignore: unawaited_futures | 224 | // ignore: unawaited_futures |
225 | _bounceDragController.reverse(); | 225 | _bounceDragController.reverse(); |
226 | 226 | ||
227 | - var canClose = true; | ||
228 | - if (widget.shouldClose != null) { | ||
229 | - _cancelClose(); | ||
230 | - canClose = await shouldClose(); | ||
231 | - } | ||
232 | - if (canClose) { | ||
233 | - // If speed is bigger than _minFlingVelocity try to close it | ||
234 | - if (velocity > _minFlingVelocity) { | ||
235 | - _close(); | ||
236 | - } else if (hasReachedCloseThreshold) { | ||
237 | - if (widget.animationController.value > 0.0) { | ||
238 | - // ignore: unawaited_futures | ||
239 | - widget.animationController.fling(velocity: -1.0); | 227 | + Future<void> tryClose() async { |
228 | + if (widget.shouldClose != null) { | ||
229 | + _cancelClose(); | ||
230 | + bool canClose = await shouldClose(); | ||
231 | + if (canClose) { | ||
232 | + _close(); | ||
240 | } | 233 | } |
241 | - _close(); | ||
242 | } else { | 234 | } else { |
243 | - _cancelClose(); | 235 | + _close(); |
236 | + } | ||
237 | + } | ||
238 | + | ||
239 | + // If speed is bigger than _minFlingVelocity try to close it | ||
240 | + if (velocity > _minFlingVelocity) { | ||
241 | + tryClose(); | ||
242 | + } else if (hasReachedCloseThreshold) { | ||
243 | + if (widget.animationController.value > 0.0) { | ||
244 | + // ignore: unawaited_futures | ||
245 | + widget.animationController.fling(velocity: -1.0); | ||
244 | } | 246 | } |
247 | + tryClose(); | ||
245 | } else { | 248 | } else { |
246 | _cancelClose(); | 249 | _cancelClose(); |
247 | } | 250 | } |
-
Please register or login to post a comment