canTransitionTo method

  1. @override
bool canTransitionTo(
  1. TransitionRoute nextRoute
)
override

Returns true if this route supports a transition animation that runs when nextRoute is pushed on top of it or when nextRoute is popped off of it.

Subclasses can override this method to restrict the set of routes they need to coordinate transitions with.

If true, and nextRoute.canTransitionFrom() is true, then the ModalRoute.buildTransitions secondaryAnimation will run from 0.0 - 1.0 when nextRoute is pushed on top of this one. Similarly, if the nextRoute is popped off of this route, the secondaryAnimation will run from 1.0 - 0.0.

If false, this route's ModalRoute.buildTransitions secondaryAnimation parameter value will be kAlwaysDismissedAnimation. In other words, this route will not animate when nextRoute is pushed on top of it or when nextRoute is popped off of it.

Returns true by default.

See also:

Implementation

@override
bool canTransitionTo(TransitionRoute<dynamic> nextRoute) {
  // Don't perform outgoing animation if the next route is a fullscreen dialog.
  final bool nextRouteIsNotFullscreen = (nextRoute is! PageRoute<T>) || !nextRoute.fullscreenDialog;

  // If the next route has a delegated transition, then this route is able to
  // use that delegated transition to smoothly sync with the next route's
  // transition.
  final bool nextRouteHasDelegatedTransition = nextRoute is ModalRoute<T>
    && nextRoute.delegatedTransition != null;

  // Otherwise if the next route has the same route transition mixin as this
  // one, then this route will already be synced with its transition.
  return nextRouteIsNotFullscreen &&
    ((nextRoute is CupertinoRouteTransitionMixin) || nextRouteHasDelegatedTransition);
}