buildTransitions<T> method

  1. @override
Widget buildTransitions<T>(
  1. PageRoute<T> route,
  2. BuildContext context,
  3. Animation<double> animation,
  4. Animation<double> secondaryAnimation,
  5. Widget child,
)
override

Wraps the child with one or more transition widgets which define how route arrives on and leaves the screen.

Subclasses override this method to create a transition animation.

The MaterialPageRoute.buildTransitions method is an example of a method that uses this to build a transition. It looks up the current PageTransitionsTheme with Theme.of(context).pageTransitionsTheme and delegates to this method with a PageTransitionsBuilder based on the theme's ThemeData.platform.

Implementation

@override
Widget buildTransitions<T>(
  PageRoute<T> route,
  BuildContext context,
  Animation<double> animation,
  Animation<double> secondaryAnimation,
  Widget child,
) {
  final Widget widget = CupertinoRouteTransitionMixin.buildPageTransitions(
    route,
    context,
    animation,
    secondaryAnimation,
    child,
  );

  if (widget is CupertinoPageTransition) {
    return SlideTransition(
      position: Tween(begin: Offset.zero, end: const Offset(-1.0, 0.0))
          .animate(
            route.popGestureInProgress
                ? animation
                : CurvedAnimation(
                    parent: animation,
                    curve: Curves.linearToEaseOut,
                    reverseCurve: Curves.linearToEaseOut.flipped,
                  ),
          ),
      child: SlideTransition(
        position: Tween(begin: const Offset(1.0, 0.0), end: Offset.zero)
            .animate(
              route.popGestureInProgress
                  ? secondaryAnimation
                  : CurvedAnimation(
                      parent: secondaryAnimation,
                      curve: Curves.linearToEaseOut,
                      reverseCurve: Curves.easeInToLinear,
                    ),
            ),
        child: widget.child,
      ),
    );
  } else {
    return widget;
  }
}