admin管理员组文章数量:1310283
In Flutter, how do I push a page without any transition animation but when I pop it, I'd like the page to slide from top to bottom.
The following code works partially. It disables the animation during push, but it also disables the animation during pop.
// Push without animation
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => MyNewPage(),
transitionDuration: Duration.zero, // No animation when pushing
),
);
// Pop with the default animation (does not work)
Navigator.pop(context);
In Flutter, how do I push a page without any transition animation but when I pop it, I'd like the page to slide from top to bottom.
The following code works partially. It disables the animation during push, but it also disables the animation during pop.
// Push without animation
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => MyNewPage(),
transitionDuration: Duration.zero, // No animation when pushing
),
);
// Pop with the default animation (does not work)
Navigator.pop(context);
Share
Improve this question
asked Feb 3 at 11:28
user246392user246392
3,02712 gold badges69 silver badges125 bronze badges
1 Answer
Reset to default 1This happens because you are creating a PageRouteBuilder
without a transition, so transitionDuration
does not yet have any impact.
Try the following PageRouteBuilder
with a slide transition:
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => const MyNewPage(),
transitionDuration: Duration.zero,
// reverseTransitionDuration: Duration.zero,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0);
const end = Offset.zero;
const curve = Curves.ease;
var tween = Tween(begin: begin, end: end).chain(
CurveTween(curve: curve)
);
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
);
Now, you should be able to use transitionDuration
to achieve the desired effect. reverseTransitionDuration
can be used if you want to do the opposite (no transition during pop
).
For completeness, if you actually want different transitions for push
and pop
, you can use animation.status
and conditionally return a different transition whether the animation is forward
or reverse
.
本文标签: dartFlutter Disable push transition animation but enable it for popStack Overflow
版权声明:本文标题:dart - Flutter: Disable push transition animation but enable it for pop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741825055a2399593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论