【问题标题】:How to pop screen without animation in Flutter如何在 Flutter 中弹出没有动画的屏幕
【发布时间】:2019-12-15 21:18:03
【问题描述】:

基本上我想Navigator.of(context).pop(); 但没有动画。

通过阅读文档,我发现您只能在推送路线时覆盖此动画。就我而言,我事先不知道在删除路线时是否要显示弹出动画,所以我需要一个解决方案,允许我在调用 pop() 时指定是否需要此动画

这可能吗?

【问题讨论】:

  • @SharadPaghdal 这不起作用,因为根据用户输入,我可能需要显示或不显示弹出动画。覆盖buildTransitions 将在推送路由之前预定义是否播放动画。

标签: flutter


【解决方案1】:

要创建/弹出没有动画的页面,您可以像这样创建自定义页面。

class NoAnimationPage extends Page<dynamic> {
  const NoAnimationPage({
    LocalKey? key,
    required this.child,
  }) : super(key: key);

  final Widget child;

  @override
  Route<dynamic> createRoute(BuildContext context) => PageRouteBuilder<dynamic>(
        settings: this,
        pageBuilder: (_, __, ___) => child, 
        // don't wrap in an animation to create a page without animation.
  );
}

然后使用NoAnimationPage 代替MaterialPageCupertinoPage

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-25
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2020-05-22
    • 2020-11-08
    • 2020-12-11
    相关资源
    最近更新 更多