generate<R, P extends RouteParams> method

  1. @override
RouteCreator<R, P> generate<R, P extends RouteParams>(
  1. AppRoute<R, P> appRoute,
  2. TransitionType? transition,
  3. Duration? transitionDuration,
  4. RouteTransitionsBuilder? transitionsBuilder
)

Implementation

@override
RouteCreator<R, P> generate<R, P extends RouteParams>(
    AppRoute<R, P> appRoute, TransitionType? transition, Duration? transitionDuration, transitionsBuilder) {
  return (name, params) {
    _log.info("Creating route for ${appRoute} using ${params}");
    if (appRoute is CompletableAppRoute<R, P>) {
      _log.info(" [${appRoute.route}] is CompletableRoute");
      return CompletableRouteAdapter<R>((context) {
        return appRoute.handleAny(context, params, (context, appRoute, params) {
          final Route<dynamic> Function(String?, RouteParams) c =
              generateAny(appRoute, TransitionType.native, Duration(milliseconds: 300), null);
          final route = c(appRoute.routeTitle(params), params);
          return Navigator.of(context).push(route);
        }).then((_) => _ as R);
      });
    } else if (appRoute is AppPageRoute<R, P>) {
      _log.info(" [${appRoute.route}] is AppPageRoute");
      final routeSettings = PathRouteSettings.ofAppRoute(
        appRoute,
        routeParams: params,
      );
      // ignore: missing_required_param
      return PlatformPageRoute<R>(
        settings: routeSettings,
        builder: (context) {
          /// Do we support nested navigation?
          if (allowNestedModals) {
            /// Previous behavior
            final nn = Provided.find<NestedNavigatorContainer>(context);
            Widget? _p;
            if (nn != null) {
              return _p ??= appRoute.handle(context, params);
            }
          }
          return appRoute.handleAny(context, params);
        },
        fullscreenDialog: transition == TransitionType.nativeModal,
      );
    } else {
      throw "Invalid route type ${appRoute.runtimeType}";
    }
  };
}