Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created May 27, 2019 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinusX/cae41835ef7b0d89ad66ec8b4153dc67 to your computer and use it in GitHub Desktop.
Save MarcinusX/cae41835ef7b0d89ad66ec8b4153dc67 to your computer and use it in GitHub Desktop.
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