Skip to content

Instantly share code, notes, and snippets.

@diefferson
Created February 20, 2020 15:46
Show Gist options
  • Save diefferson/989bcfb1068cb6c65848b9435669baa0 to your computer and use it in GitHub Desktop.
Save diefferson/989bcfb1068cb6c65848b9435669baa0 to your computer and use it in GitHub Desktop.
Flutter Slide Transition
class MyCustomPageRoute extends MaterialPageRoute {
final Widget previousPage;
MyCustomPageRoute({this.previousPage, WidgetBuilder builder, RouteSettings settings}) : super(builder: builder, settings: settings);
@override
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget currentPage) {
Animation<Offset> _slideAnimationPage1 = Tween<Offset>(begin: Offset(0.0, 0.0), end: Offset(-1.0, 0.0)).animate(animation);
Animation<Offset> _slideAnimationPage2 = Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0)).animate(animation);
return Stack(
children: <Widget>[
SlideTransition(position: _slideAnimationPage1, child: previousPage),
SlideTransition(position: _slideAnimationPage2, child: currentPage),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment