Skip to content

Instantly share code, notes, and snippets.

@miguelpruivo
Created April 29, 2019 23:07
Show Gist options
  • Save miguelpruivo/59009b3ad9e743da10a6a2d586d46582 to your computer and use it in GitHub Desktop.
Save miguelpruivo/59009b3ad9e743da10a6a2d586d46582 to your computer and use it in GitHub Desktop.
Back swipe navigation gesture
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