In my Flutter project, that has multiple screens, I want to create one screen with 2 buttons:
Navigator.pop()
with a transition where the current screen disappears to the rightNavigator.pop()
, but this time the screen disappears to the bottomEvery example I've found so far allows me to set only one possible transition when I pop my screen.
Also, I use named routes to navigate in my app.
How can I customize the pop animation according to the button clicked by the user?
Thanks.
whatever you define as a route animation it would be reverse and use as pop navigation .
in your case you can use different animations for pushing each one .
you can create your custom one and define the animation and use it instead of material page router
import 'package:flutter/material.dart';
class MyCustomRoute extends PageRouteBuilder {
final Widget widget;
MyCustomRoute({this.widget})
: super(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return widget;
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return new ScaleTransition(
scale: new Tween<double>(
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: animation,
curve: Interval(
0.00,
0.50,
curve: Curves.bounceIn,
),
),
),
child: ScaleTransition(
scale: Tween<double>(
begin: 1.5,
end: 1.0,
).animate(
CurvedAnimation(
parent: animation,
curve: Interval(
0.50,
1.00,
curve: Curves.easeIn,
),
),
),
child: child,
),
);
}
);
}
to implement
onPressed: () {
Navigator.push(context,
new MyCustomRoute (widget: Secondpage()));
},
to pop
onPressed: () {
Navigator.pop();// will reverse the animation
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With