generator method

RouteFactory generator()

Generates the RouteFactory which builds a Route on request.

These routes are built using the NyRouterRoutes addRoute method.

Implementation

RouteFactory generator() {
  return (settings) {
    if (settings.name == null) return null;

    Uri? uriSettingName;
    try {
      uriSettingName = Uri.parse(settings.name!);
    } on FormatException catch (e) {
      NyLogger.error(e.toString());
    }

    String routeName = settings.name!;
    if (uriSettingName != null) {
      routeName = uriSettingName.path;
    }

    final NyRouterRoute? route = _routeNameMappings[routeName];

    if (route == null) return null;

    ArgumentsWrapper? argumentsWrapper;
    if (settings.arguments is ArgumentsWrapper) {
      argumentsWrapper = settings.arguments as ArgumentsWrapper?;
    } else {
      argumentsWrapper = ArgumentsWrapper();
      argumentsWrapper.baseArguments = NyArgument(settings.arguments);
    }

    if (argumentsWrapper == null) {
      argumentsWrapper = ArgumentsWrapper();
    }

    if (uriSettingName != null && uriSettingName.queryParameters.isNotEmpty) {
      argumentsWrapper.queryParameters =
          NyQueryParameters(uriSettingName.queryParameters);
    }

    final BaseArguments? baseArgs = argumentsWrapper.baseArguments;
    final NyQueryParameters? queryParameters =
        argumentsWrapper.queryParameters;

    if (argumentsWrapper.pageTransitionSettings == null) {
      argumentsWrapper.pageTransitionSettings = PageTransitionSettings();
    }

    if (route.pageTransitionSettings == null) {
      route.pageTransitionSettings = PageTransitionSettings();
    }

    return PageTransition(
        child: StatefulBuilder(
            builder: (BuildContext context, StateSetter setState) {
          return route.builder(context, baseArgs ?? route.defaultArgs,
              queryParameters ?? route.queryParameters);
        }),
        type: argumentsWrapper.pageTransitionType ?? route.pageTransitionType,
        settings: settings,
        duration: _getPageTransitionDuration(route, argumentsWrapper),
        alignment: _getPageTransitionAlignment(route, argumentsWrapper),
        reverseDuration:
            _getPageTransitionReversedDuration(route, argumentsWrapper),
        matchingBuilder:
            _getPageTransitionMatchingBuilder(route, argumentsWrapper),
        childCurrent: _getPageTransitionChildCurrent(route, argumentsWrapper),
        curve: _getPageTransitionCurve(route, argumentsWrapper),
        ctx: _getPageTransitionContext(route, argumentsWrapper),
        inheritTheme: _getPageTransitionInheritTheme(route, argumentsWrapper),
        fullscreenDialog:
            _getPageTransitionFullscreenDialog(route, argumentsWrapper),
        opaque: _getPageTransitionOpaque(route, argumentsWrapper),
        isIos: _getPageTransitionIsIos(route, argumentsWrapper));
  };
}