Skip to content

Instantly share code, notes, and snippets.

@PreyeaRegmi
Created June 15, 2021 09:07
Show Gist options
  • Save PreyeaRegmi/f612b122a0b11278f75afc7216bf781b to your computer and use it in GitHub Desktop.
Save PreyeaRegmi/f612b122a0b11278f75afc7216bf781b to your computer and use it in GitHub Desktop.
A simple drag behaviour added to bouncing "Swipe to Start" widget.
//A simple container with a SingleChildScrollView. The trick is to set the child of SingleChildScrollView height
//exceed the height of parent scroll widget so it can be scrolled. The BouncingScrollPhysics helps the scroll retain its
//original position if it doesn't cross the threshold to play reveal animation.
//This widget is added by _getInitScreenWidgets() method
Positioned(
right: 0,
left: 0,
bottom: 0,
child: Container(
height: widget.height * .5,
child: SingleChildScrollView(
controller: _scrollController,
physics: BouncingScrollPhysics(),
child: Container(
height: widget.height * .5 + .1,
// color:Colors.yellow,
),
),
),
),
//Intercepts the bounce animation and start dragg animation
void _handleSwipe() {
_swipeUpBounceAnimationController.stop(canceled: true);
double dy = _scrollController.position.pixels;
double scrollRatio =
math.min(1.0, _scrollController.position.pixels / _swipeDistance);
//If user scroll 70% of the scrolling region we proceed towards reveal animation
if (scrollRatio > .7)
_playRevealAnimation();
else
setState(() {
_swipeUpDy = dy * -1;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment