ifRouteChanged method

bool ifRouteChanged(
  1. BuildContext context
)

Return true if the current route is NOT the same route of when the interceptor was created.

This is useful if you want to create an interceptor that only runs when the current route is the same route of when the interceptor was created:

bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
   if (info.ifRouteChanged(context)) return false;
   ...
 }

This method can only be called if the context parameter was passed to the BackButtonInterceptor.add method.

Implementation

bool ifRouteChanged(BuildContext context) {
  if (routeWhenAdded == null)
    throw AssertionError("The ifRouteChanged() method "
        "can only be called if the context parameter was "
        "passed to the BackButtonInterceptor.add() method.");

  return !identical(currentRoute(context), routeWhenAdded);
}