Transition animation for Flutter Navigation
First you have to add the package dependency in pubspec.yml
transition_x: ^latest
Get th version from pub.dev
In your push() 0r pushReplacement() add the Transition like this.
Navigator.of(context).push(
TransitionX(
widget: Register(),
transitionType: TransitionType.slideToLeftWithFade,
bounce: false,
),
);
In your Material App's onGenerateRoute
add the transitions. Make sure that the the route name you are using in onGenerateRoute
is not defined in the routes list or anywhere in the Material App
onGenerateRoute: (settings) {
switch (settings.name) {
case '/home':
return TransitionX(
widget: HomeScreen(),
transitionType: TransitionType.slideToLeftWithFade,
bounce: false,
);
case '/login':
return TransitionX(
widget: Login(),
transitionType: TransitionType.slideToLeftWithFade,
bounce: false,
);
case '/register':
return TransitionX(
widget: Register(),
transitionType: TransitionType.slideToLeftWithFade,
bounce: false,
);
default:
return TransitionX(
widget: Unknown(),
transitionType: TransitionType.slideToLeftWithFade,
bounce: false,
);
}
}
- bool bounce
- Sets if the transition hase bounce effect.
- Duration duration
- Sets the duration of Animation.
- TransitionType transitionType
- Sets the Transition animation Type
- Curve curve
- Sets Curve for animation type
TransitionType.slideToRightWithFade
- Sets Curve for animation type