library page_transition; import 'package:flutter/material.dart'; enum PageTransitionType { fade, rightToLeft, leftToRight, upToDown, downToUp, scale, rotate, size, rightToLeftWithFade, leftToRightWithFade, } class PageTransition extends PageRouteBuilder { final Widget child; final PageTransitionType type; final Curve curve; final Alignment alignment; final Duration duration; PageTransition({ Key key, @required this.child, @required this.type, this.curve = Curves.linear, this.alignment, this.duration = const Duration(milliseconds: 300), }) : super( pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) { return child; }, transitionDuration: duration, transitionsBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { switch (type) { case PageTransitionType.fade: return FadeTransition(opacity: animation, child: child); break; case PageTransitionType.rightToLeft: return SlideTransition( transformHitTests: false, position: new Tween( begin: const Offset(1.0, 0.0), end: Offset.zero, ).animate(animation), child: new SlideTransition( position: new Tween( begin: Offset.zero, end: const Offset(-1.0, 0.0), ).animate(secondaryAnimation), child: child, ), ); break; case PageTransitionType.leftToRight: return SlideTransition( transformHitTests: false, position: Tween( begin: const Offset(-1.0, 0.0), end: Offset.zero, ).animate(animation), child: new SlideTransition( position: new Tween( begin: Offset.zero, end: const Offset(1.0, 0.0), ).animate(secondaryAnimation), child: child, ), ); break; case PageTransitionType.upToDown: return SlideTransition( transformHitTests: false, position: Tween( begin: const Offset(0.0, -1.0), end: Offset.zero, ).animate(animation), child: new SlideTransition( position: new Tween( begin: Offset.zero, end: const Offset(0.0, 1.0), ).animate(secondaryAnimation), child: child, ), ); break; case PageTransitionType.downToUp: return SlideTransition( transformHitTests: false, position: Tween( begin: const Offset(0.0, 1.0), end: Offset.zero, ).animate(animation), child: new SlideTransition( position: new Tween( begin: Offset.zero, end: const Offset(0.0, -1.0), ).animate(secondaryAnimation), child: child, ), ); break; case PageTransitionType.scale: return ScaleTransition( alignment: alignment, scale: CurvedAnimation( parent: animation, curve: Interval( 0.00, 0.50, curve: Curves.bounceInOut, ), ), child: child, ); break; case PageTransitionType.rotate: return new RotationTransition( alignment: alignment, turns: animation, child: new ScaleTransition( alignment: alignment, scale: animation, child: FadeTransition( opacity: animation, child: child, ), ), ); break; case PageTransitionType.size: return Align( alignment: alignment, child: SizeTransition( sizeFactor: CurvedAnimation( parent: animation, curve: curve, ), child: child, ), ); break; case PageTransitionType.rightToLeftWithFade: return SlideTransition( position: Tween( begin: const Offset(1.0, 0.0), end: Offset.zero, ).animate(animation), child: FadeTransition( opacity: animation, child: SlideTransition( position: Tween( begin: Offset.zero, end: const Offset(-1.0, 0.0), ).animate(secondaryAnimation), child: child, ), ), ); break; case PageTransitionType.leftToRightWithFade: return SlideTransition( position: Tween( begin: const Offset(-1.0, 0.0), end: Offset.zero, ).animate(animation), child: FadeTransition( opacity: animation, child: SlideTransition( position: Tween( begin: Offset.zero, end: const Offset(1.0, 0.0), ).animate(secondaryAnimation), child: child, ), ), ); break; default: return FadeTransition(opacity: animation, child: child); } }); }