Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter custom page route and iOS swipe back gesture

In my app I have extended MaterialPageRoute to disable page transition animations.

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. How do I re-enable it? I don't care about animating anything, I just want swipe to go back to work.

like image 773
Lee Avatar asked Sep 06 '25 19:09

Lee


1 Answers

if you don't need any animation you can do like that:

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

like image 194
Kherel Avatar answered Sep 09 '25 00:09

Kherel