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,
)

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,
) {
  // 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 = isPopGestureInProgress(route);
  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,
        route.popGesture ?? Get.defaultPopGesture
            ? CupertinoBackGestureDetector<T>(
                gestureWidth:
                    route.gestureWidth?.call(context) ?? _kBackGestureWidth,
                enabledCallback: () => _isPopGestureEnabled<T>(route),
                onStartPopGesture: () => _startPopGesture<T>(route),
                child: 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,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.downToUp:
        return SlideDownTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.upToDown:
        return SlideTopTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.noTransition:
        return route.popGesture ?? Get.defaultPopGesture
            ? CupertinoBackGestureDetector<T>(
                gestureWidth:
                    route.gestureWidth?.call(context) ?? _kBackGestureWidth,
                enabledCallback: () => _isPopGestureEnabled<T>(route),
                onStartPopGesture: () => _startPopGesture<T>(route),
                child: child)
            : child;

      case Transition.rightToLeft:
        return SlideRightTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.zoom:
        return ZoomInTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.fadeIn:
        return FadeInTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.rightToLeftWithFade:
        return RightToLeftFadeTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.leftToRightWithFade:
        return LeftToRightFadeTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.cupertino:
        return CupertinoPageTransition(
          primaryRouteAnimation: animation,
          secondaryRouteAnimation: secondaryAnimation,
          linearTransition: linearTransition,
          child: CupertinoBackGestureDetector<T>(
            gestureWidth:
                route.gestureWidth?.call(context) ?? _kBackGestureWidth,
            enabledCallback: () => _isPopGestureEnabled<T>(route),
            onStartPopGesture: () => _startPopGesture<T>(route),
            child: child,
          ),
        );

      case Transition.size:
        return SizeTransitions().buildTransitions(
            context,
            route.curve!,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.fade:
        return const FadeUpwardsPageTransitionsBuilder().buildTransitions(
            route,
            context,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.topLevel:
        return const ZoomPageTransitionsBuilder().buildTransitions(
            route,
            context,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.native:
        return const PageTransitionsTheme().buildTransitions(
            route,
            context,
            iosAnimation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

      case Transition.circularReveal:
        return CircularRevealTransition().buildTransitions(
            context,
            route.curve,
            route.alignment,
            animation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);

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

        return const PageTransitionsTheme().buildTransitions(
            route,
            context,
            iosAnimation,
            secondaryAnimation,
            route.popGesture ?? Get.defaultPopGesture
                ? CupertinoBackGestureDetector<T>(
                    gestureWidth: route.gestureWidth?.call(context) ??
                        _kBackGestureWidth,
                    enabledCallback: () => _isPopGestureEnabled<T>(route),
                    onStartPopGesture: () => _startPopGesture<T>(route),
                    child: child)
                : child);
    }
  }
}