buildPageTransitions<T> static method

Widget buildPageTransitions<T>(
  1. PageRoute<T> rawRoute,
  2. BuildContext context,
  3. Animation<double> animation,
  4. Animation<double> secondaryAnimation,
  5. Widget child, {
  6. bool limitedSwipe = false,
  7. double initialOffset = 0,
})

Returns a CupertinoFullscreenDialogTransition if route is a full screen dialog, otherwise a CupertinoPageTransition is returned.

Used by CupertinoPageRoute.buildTransitions.

This method can be applied to any PageRoute, not just CupertinoPageRoute. It's typically used to provide a Cupertino style horizontal transition for material widgets when the target platform is TargetPlatform.iOS.

See also:

Implementation

static Widget buildPageTransitions<T>(
  PageRoute<T> rawRoute,
  BuildContext context,
  Animation<double> animation,
  Animation<double> secondaryAnimation,
  Widget child, {
  bool limitedSwipe = false,
  double initialOffset = 0,
}) {
  // Check if the route has an animation that's currently participating
  // in a back swipe gesture.
  //
  // In the middle of a back gesture drag, let the transition be linear to
  // match finger motions.
  final route = rawRoute as GetPageRoute<T>;
  final linearTransition = route.popGestureInProgress;
  final finalCurve = route.curve ?? Get.defaultTransitionCurve;
  final hasCurve = route.curve != null;
  if (route.fullscreenDialog && route.transition == null) {
    return CupertinoFullscreenDialogTransition(
      primaryRouteAnimation: hasCurve
          ? CurvedAnimation(parent: animation, curve: finalCurve)
          : animation,
      secondaryRouteAnimation: secondaryAnimation,
      linearTransition: linearTransition,
      child: child,
    );
  } else {
    if (route.customTransition != null) {
      return route.customTransition!.buildTransition(
        context,
        finalCurve,
        route.alignment,
        animation,
        secondaryAnimation,
        GetBackGestureDetector<T>(
          popGestureEnable: () =>
              _isPopGestureEnabled(route, canSwipe(route), context),
          onStartPopGesture: () {
            assert(_isPopGestureEnabled(route, canSwipe(route), context));
            return _startPopGesture(route);
          },
          limitedSwipe: limitedSwipe,
          gestureWidth:
              route.gestureWidth?.call(context) ?? _kBackGestureWidth,
          initialOffset: initialOffset,
          child: child,
        ),
      );
    }

    /// Apply the curve by default...
    final iosAnimation = animation;
    animation = CurvedAnimation(parent: animation, curve: finalCurve);

    switch (route.transition ?? Get.defaultTransition) {
      case Transition.leftToRight:
        return SlideLeftTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.downToUp:
        return SlideDownTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.upToDown:
        return SlideTopTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.noTransition:
        return GetBackGestureDetector<T>(
          popGestureEnable: () =>
              _isPopGestureEnabled(route, canSwipe(route), context),
          onStartPopGesture: () {
            assert(_isPopGestureEnabled(route, canSwipe(route), context));
            return _startPopGesture(route);
          },
          limitedSwipe: limitedSwipe,
          gestureWidth:
              route.gestureWidth?.call(context) ?? _kBackGestureWidth,
          initialOffset: initialOffset,
          child: child,
        );

      case Transition.rightToLeft:
        return SlideRightTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.zoom:
        return ZoomInTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.fadeIn:
        return FadeInTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.rightToLeftWithFade:
        return RightToLeftFadeTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.leftToRightWithFade:
        return LeftToRightFadeTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.cupertino:
        return CupertinoPageTransition(
            primaryRouteAnimation: animation,
            secondaryRouteAnimation: secondaryAnimation,
            linearTransition: linearTransition,
            child: GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.size:
        return SizeTransitions().buildTransitions(
            context,
            route.curve!,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.fade:
        return const FadeUpwardsPageTransitionsBuilder().buildTransitions(
            route,
            context,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.topLevel:
        return const ZoomPageTransitionsBuilder().buildTransitions(
            route,
            context,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.native:
        return const PageTransitionsTheme().buildTransitions(
            route,
            context,
            iosAnimation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      case Transition.circularReveal:
        return CircularRevealTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(_isPopGestureEnabled(route, canSwipe(route), context));
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));

      default:
        final customTransition = GetRoot.of(context).config.customTransition;

        if (customTransition != null) {
          return customTransition.buildTransition(context, route.curve,
              route.alignment, animation, secondaryAnimation, child);
        }

        PageTransitionsTheme pageTransitionsTheme =
            Theme.of(context).pageTransitionsTheme;

        return pageTransitionsTheme.buildTransitions(
            route,
            context,
            iosAnimation,
            secondaryAnimation,
            GetBackGestureDetector<T>(
              popGestureEnable: () =>
                  _isPopGestureEnabled(route, canSwipe(route), context),
              onStartPopGesture: () {
                assert(
                  _isPopGestureEnabled(route, canSwipe(route), context),
                );
                return _startPopGesture(route);
              },
              limitedSwipe: limitedSwipe,
              gestureWidth:
                  route.gestureWidth?.call(context) ?? _kBackGestureWidth,
              initialOffset: initialOffset,
              child: child,
            ));
    }
  }
}