buildSecondaryTransitionForPreviousRoute method

Widget buildSecondaryTransitionForPreviousRoute(
  1. BuildContext context,
  2. Animation<double> secondaryAnimation,
  3. Widget child
)

Override this method to wrap the child with one or more transition widgets that define how the previous route will hides/shows when this route is pushed on top of it or when then this route is popped off of it.

This method is called only when handleSecondaryAnimationTransitionForPreviousRoute returns true and it will override the transition defined by secondaryAnimation inside buildTransitions. In this case, then the previous route's ModalRoute.buildTransitions secondaryAnimation value will be kAlwaysDismissedAnimation.

By default, the child (which contains the widget returned by previous route's ModalRoute.buildPage) is not wrapped in any transition widgets.

When the Navigator pushes this route on the top of its stack, this method together with secondaryAnimation can be used to define how the previous route that was on the top of the stack leaves the screen. Similarly when the topmost route is popped, the secondaryAnimation can be used to define how the previous route below it reappears on the screen.

When the Navigator pushes this new route on the top of its stack, the old topmost route's secondaryAnimation runs from 0.0 to 1.0. When the Navigator pops the topmost route, the secondaryAnimation for the route below it runs from 1.0 to 0.0.

The example below adds a transition that's driven by the secondaryAnimation. When the previous route disappears because this route has been pushed on top of it, it translates to right. And the opposite when the route is exposed because this topmost route has been popped off.

return SlideTransition(
  position: TweenOffset(
    begin: Offset.zero,
    end: const Offset(0.0, 1.0),
  ).animate(secondaryAnimation),
  child: child,
);

 * `context`: The context in which the route is being built.
 * [secondaryAnimation]: When the Navigator pushes this route
   on the top of its stack, the previous topmost route's [secondaryAnimation]
   runs from 0.0 to 1.0. When the [Navigator] pops the topmost route, the
   [secondaryAnimation] for the route below it runs from 1.0 to 0.0.
 * `child`, the page contents from the previous route by
    previous route's [buildPage].

Implementation

Widget buildSecondaryTransitionForPreviousRoute(
  BuildContext context,
  Animation<double> secondaryAnimation,
  Widget child,
) {
  return child;
}