Committed by
GitHub
Merge pull request #22 from jamesblasco/small_bug_fixes
Small bug fixes
Showing
2 changed files
with
29 additions
and
11 deletions
| @@ -18,7 +18,7 @@ class ModalInsideModal extends StatelessWidget { | @@ -18,7 +18,7 @@ class ModalInsideModal extends StatelessWidget { | ||
| 18 | child: ListView( | 18 | child: ListView( |
| 19 | shrinkWrap: true, | 19 | shrinkWrap: true, |
| 20 | controller: scrollController, | 20 | controller: scrollController, |
| 21 | - physics: BouncingScrollPhysics(), | 21 | + physics: ClampingScrollPhysics(), |
| 22 | children: ListTile.divideTiles( | 22 | children: ListTile.divideTiles( |
| 23 | context: context, | 23 | context: context, |
| 24 | tiles: List.generate( | 24 | tiles: List.generate( |
| @@ -13,7 +13,7 @@ import 'package:flutter/widgets.dart'; | @@ -13,7 +13,7 @@ import 'package:flutter/widgets.dart'; | ||
| 13 | 13 | ||
| 14 | const Duration _bottomSheetDuration = Duration(milliseconds: 400); | 14 | const Duration _bottomSheetDuration = Duration(milliseconds: 400); |
| 15 | const double _minFlingVelocity = 500.0; | 15 | const double _minFlingVelocity = 500.0; |
| 16 | -const double _closeProgressThreshold = 0.5; | 16 | +const double _closeProgressThreshold = 0.6; |
| 17 | const double _willPopThreshold = 0.8; | 17 | const double _willPopThreshold = 0.8; |
| 18 | 18 | ||
| 19 | typedef ScrollWidgetBuilder = Widget Function( | 19 | typedef ScrollWidgetBuilder = Widget Function( |
| @@ -243,14 +243,30 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -243,14 +243,30 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 243 | 243 | ||
| 244 | void _handleScrollUpdate(ScrollNotification notification) { | 244 | void _handleScrollUpdate(ScrollNotification notification) { |
| 245 | if (notification.metrics.pixels <= notification.metrics.minScrollExtent) { | 245 | if (notification.metrics.pixels <= notification.metrics.minScrollExtent) { |
| 246 | - //Check if listener is same from scrollController | ||
| 247 | if (!_scrollController.hasClients) return; | 246 | if (!_scrollController.hasClients) return; |
| 248 | 247 | ||
| 249 | - if (_scrollController.position.pixels != notification.metrics.pixels) { | 248 | + // Check if listener is same from scrollController. |
| 249 | + // TODO: Improve the way it checks if it the same view controller | ||
| 250 | + // Use PrimaryScrollController | ||
| 251 | + if (_scrollController.position.pixels != notification.metrics.pixels && | ||
| 252 | + !(_scrollController.position.pixels == 0 && | ||
| 253 | + notification.metrics.pixels >= 0)) { | ||
| 250 | return; | 254 | return; |
| 251 | } | 255 | } |
| 256 | + // Clamping Scroll Physics end with a ScrollEndNotification with a DragEndDetail class | ||
| 257 | + // while Bouncing Scroll Physics or other physics that Overflow don't return a drag end info | ||
| 258 | + | ||
| 259 | + // We use the velocity from DragEndDetail in case it is available | ||
| 260 | + if (notification is ScrollEndNotification && | ||
| 261 | + notification.dragDetails != null) { | ||
| 262 | + _handleDragEnd(notification.dragDetails.primaryVelocity); | ||
| 263 | + _velocityTracker = null; | ||
| 264 | + _startTime = null; | ||
| 265 | + return; | ||
| 266 | + } | ||
| 267 | + // Otherwise the calculate the velocity with a VelocityTracker | ||
| 252 | DragUpdateDetails dragDetails; | 268 | DragUpdateDetails dragDetails; |
| 253 | - if (notification is ScrollStartNotification) { | 269 | + if (_velocityTracker == null) { |
| 254 | _velocityTracker = VelocityTracker(); | 270 | _velocityTracker = VelocityTracker(); |
| 255 | _startTime = DateTime.now(); | 271 | _startTime = DateTime.now(); |
| 256 | } | 272 | } |
| @@ -262,11 +278,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -262,11 +278,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 262 | } | 278 | } |
| 263 | if (dragDetails != null) { | 279 | if (dragDetails != null) { |
| 264 | final duration = _startTime.difference(DateTime.now()); | 280 | final duration = _startTime.difference(DateTime.now()); |
| 265 | - final offset = Offset(0, _scrollController.offset); | 281 | + final offset = Offset(0, notification.metrics.pixels); |
| 266 | _velocityTracker.addPosition(duration, offset); | 282 | _velocityTracker.addPosition(duration, offset); |
| 267 | _handleDragUpdate(dragDetails.primaryDelta); | 283 | _handleDragUpdate(dragDetails.primaryDelta); |
| 268 | } else if (isDragging) { | 284 | } else if (isDragging) { |
| 269 | final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy; | 285 | final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy; |
| 286 | + _velocityTracker = null; | ||
| 287 | + _startTime = null; | ||
| 270 | _handleDragEnd(velocity); | 288 | _handleDragEnd(velocity); |
| 271 | } | 289 | } |
| 272 | } | 290 | } |
| @@ -285,7 +303,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -285,7 +303,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 285 | Widget build(BuildContext context) { | 303 | Widget build(BuildContext context) { |
| 286 | final bounceAnimation = CurvedAnimation( | 304 | final bounceAnimation = CurvedAnimation( |
| 287 | parent: _bounceDragController, | 305 | parent: _bounceDragController, |
| 288 | - curve: widget.animationCurve ?? Curves.easeOutSine, | 306 | + curve: Curves.easeOutSine, |
| 289 | ); | 307 | ); |
| 290 | 308 | ||
| 291 | var child = widget.builder(context, _scrollController); | 309 | var child = widget.builder(context, _scrollController); |
| @@ -299,17 +317,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -299,17 +317,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 299 | } | 317 | } |
| 300 | 318 | ||
| 301 | // Todo: Add curved Animation when push and pop without gesture | 319 | // Todo: Add curved Animation when push and pop without gesture |
| 302 | - /* final Animation<double> containerAnimation = CurvedAnimation( | 320 | + final Animation<double> containerAnimation = CurvedAnimation( |
| 303 | parent: widget.animationController, | 321 | parent: widget.animationController, |
| 304 | - curve: Curves.easeOut, | ||
| 305 | - );*/ | 322 | + curve: widget.animationCurve ?? Curves.linear, |
| 323 | + ); | ||
| 306 | 324 | ||
| 307 | return AnimatedBuilder( | 325 | return AnimatedBuilder( |
| 308 | animation: widget.animationController, | 326 | animation: widget.animationController, |
| 309 | builder: (context, _) => ClipRect( | 327 | builder: (context, _) => ClipRect( |
| 310 | child: CustomSingleChildLayout( | 328 | child: CustomSingleChildLayout( |
| 311 | delegate: _ModalBottomSheetLayout( | 329 | delegate: _ModalBottomSheetLayout( |
| 312 | - widget.animationController.value, widget.expanded), | 330 | + containerAnimation.value, widget.expanded), |
| 313 | child: !widget.enableDrag | 331 | child: !widget.enableDrag |
| 314 | ? child | 332 | ? child |
| 315 | : KeyedSubtree( | 333 | : KeyedSubtree( |
-
Please register or login to post a comment