-
-
Save MarcinusX/cae41835ef7b0d89ad66ec8b4153dc67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _ExhibitionBottomSheetState extends State<ExhibitionBottomSheet> | |
with SingleTickerProviderStateMixin { | |
... | |
@override | |
Widget build(BuildContext context) { | |
return AnimatedBuilder( | |
... | |
child: GestureDetector( | |
onTap: _toggle, | |
onVerticalDragUpdate: _handleDragUpdate, //<-- Add verticalDragUpdate callback | |
onVerticalDragEnd: _handleDragEnd, //<-- Add verticalDragEnd callback | |
child: ... | |
), | |
); | |
}, | |
); | |
} | |
void _handleDragUpdate(DragUpdateDetails details) { | |
_controller.value -= details.primaryDelta / maxHeight; //<-- Update the _controller.value by the movement done by user. | |
} | |
void _handleDragEnd(DragEndDetails details) { | |
if (_controller.isAnimating || | |
_controller.status == AnimationStatus.completed) return; | |
final double flingVelocity = | |
details.velocity.pixelsPerSecond.dy / maxHeight; //<-- calculate the velocity of the gesture | |
if (flingVelocity < 0.0) | |
_controller.fling(velocity: math.max(2.0, -flingVelocity)); //<-- either continue it upwards | |
else if (flingVelocity > 0.0) | |
_controller.fling(velocity: math.min(-2.0, -flingVelocity)); //<-- or continue it downwards | |
else | |
_controller.fling(velocity: _controller.value < 0.5 ? -2.0 : 2.0); //<-- or just continue to whichever edge is closer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment