Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.