简体   繁体   English

Flutter 自定义页面路由和 iOS 向后滑动手势

[英]Flutter custom page route and iOS swipe back gesture

In my app I have extended MaterialPageRoute to disable page transition animations.在我的应用程序中,我扩展了 MaterialPageRoute 以禁用页面过渡动画。

class NoAnimationMaterialPageRoute<T> extends MaterialPageRoute<T> {
  NoAnimationMaterialPageRoute({
    @required WidgetBuilder builder,
    RouteSettings settings,
    bool maintainState = true,
    bool fullscreenDialog = false,
  }) : super(
          builder: builder,
          maintainState: maintainState,
          settings: settings,
          fullscreenDialog: fullscreenDialog,
        );

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    return child;
  }
}

This works as expected, however, it has broken the iOS swipe back gesture.这按预期工作,但是,它破坏了 iOS 向后滑动手势。 How do I re-enable it?如何重新启用它? I don't care about animating anything, I just want swipe to go back to work.我不关心任何动画,我只想滑动到 go 重新开始工作。

if you don't need any animation you can do like that:如果你不需要任何 animation 你可以这样做:

class NoAnimationMaterialPageRoute<T> extends MaterialPageRoute<T> {
  NoAnimationMaterialPageRoute({
    @required WidgetBuilder builder,
    RouteSettings settings,
    bool maintainState = true,
    bool fullscreenDialog = false,
  }) : super(
          builder: builder,
          maintainState: maintainState,
          settings: settings,
          fullscreenDialog: fullscreenDialog,
        );

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    var animation1 = Tween(begin: 1.0, end: 1.0).animate(animation);

    final theme = Theme.of(context).pageTransitionsTheme;
    return theme.buildTransitions<T>(
      this,
      context,
      animation1,
      secondaryAnimation,
      child,
    );
  }
}

But it gives you only the back swipe functionality, without visible effect, you wanted to have the visual effect of gesture, you will need to make your own version of CupertinoPageTransition但是它只给了你向后滑动的功能,没有可见的效果,你想要有手势的视觉效果,你需要制作你自己的 CupertinoPageTransition 版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM