CustomRoutePageFactoryResolver constructor
Interface for custom handling of specific Route types that are not supported out of the box by NavigatorCompatibilityOverrides.
This allows applications to integrate custom Route implementations from third-party libraries or legacy code into YxNavigation's declarative navigation system.
Purpose
NavigatorCompatibilityOverrides provides built-in support for standard Flutter route types:
- MaterialPageRoute
- CupertinoPageRoute
- ModalBottomSheetRoute
- Any ModalRoute via
modalRouteProxy
However, real-world applications may use custom Route classes with:
- Custom transition animations
- Specific route parameters (e.g., for analytics)
- Third-party library route implementations
CustomRoutePageFactoryResolver enables handling of these custom types.
Implementation
To create a custom resolver:
- Implement hasResolverFor to identify your custom Route types
- Implement resolvePage to create appropriate Page objects
Example resolver for a custom transition route:
class MyCustomResolver implements CustomRoutePageFactoryResolver {
@override
bool hasResolverFor<T>(Route<T> route) {
return route is MyCustomTransitionRoute;
}
@override
Page<Object?> resolvePage<T>({
required Completer<T?> routeCompleter,
required Route<T> route,
required LocalKey key,
}) {
final customRoute = route as MyCustomTransitionRoute<T>;
return MyCustomPage<T>(
key: key,
name: route.settings.name,
arguments: route.settings.arguments,
routeCompleter: routeCompleter,
transitionDuration: customRoute.transitionDuration,
child: Builder(
builder: (context) => customRoute.buildPage(
context,
customRoute.animation ?? kAlwaysDismissedAnimation,
customRoute.secondaryAnimation ?? kAlwaysDismissedAnimation,
),
),
);
}
}
Registration
Register your resolver with NavigatorCompatibilityOverrides:
NavigationConfigProvider(
navigatorOverrides: NavigatorCompatibilityOverrides(
customRoutePageFactoryResolver: MyCustomResolver(),
),
child: MaterialApp.router(routerConfig: config),
)
Resolution Priority
Custom resolvers are checked first, before built-in route types. This allows overriding default handling if needed.
See also:
- NavigatorCompatibilityOverrides, which uses this resolver
- Route, the base class for all navigation routes
- Page, the declarative representation of routes
Implementation
const CustomRoutePageFactoryResolver();