Created
April 29, 2019 23:07
-
-
Save miguelpruivo/59009b3ad9e743da10a6a2d586d46582 to your computer and use it in GitHub Desktop.
Back swipe navigation gesture
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 BackSwipe extends StatelessWidget { | |
final Widget child; | |
BackSwipe({Key key, this.child}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
double start = 0.0; | |
return GestureDetector( | |
onHorizontalDragStart: (details) => start = details.globalPosition.dx, | |
onHorizontalDragUpdate: (details) { | |
if (start <= MediaQuery.of(context).size.width * 0.15 && details.globalPosition.dx >= MediaQuery.of(context).size.width * 0.4) { | |
Navigator.of(context).pop(); | |
} | |
}, | |
child: child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment