routeTo function

dynamic routeTo(
  1. dynamic routeName, {
  2. dynamic data,
  3. Map<String, dynamic>? queryParameters,
  4. NavigationType navigationType = NavigationType.push,
  5. dynamic result,
  6. bool removeUntilPredicate(
    1. Route route
    )?,
  7. PageTransitionSettings? pageTransitionSettings,
  8. PageTransitionType? pageTransitionType,
  9. int? tabIndex,
  10. dynamic onPop(
    1. dynamic value
    )?,
})

Navigate to a new route.

It requires a String routeName e.g. ProfilePage.path or "/my-route"

Optional variables in data that you can pass in dynamic objects to the next widget you navigate to.

navigationType can be assigned with the following: NavigationType.push, NavigationType.pushReplace, NavigationType.pushAndRemoveUntil or NavigationType.popAndPushNamed

pageTransitionType allows you to assign a transition type for when navigating to the new route. E.g. PageTransitionType.fade or PageTransitionType.bottomToTop. See https://pub.dev/packages/page_transition to learn more.

Implementation

routeTo(dynamic routeName,
    {dynamic data,
    Map<String, dynamic>? queryParameters,
    NavigationType navigationType = NavigationType.push,
    dynamic result,
    bool Function(Route<dynamic> route)? removeUntilPredicate,
    PageTransitionSettings? pageTransitionSettings,
    PageTransitionType? pageTransitionType,
    int? tabIndex,
    Function(dynamic value)? onPop}) async {
  if (routeName is RouteView) {
    routeName = routeName.$1;
  }

  if (tabIndex != null) {
    if (data != null) {
      assert(data is Map, "Data must be of type Map");
      (data as Map<String, dynamic>).addAll({"tab-index": tabIndex});
    } else {
      data = {"tab-index": tabIndex};
    }
  }

  NyArgument nyArgument = NyArgument(data);
  if (queryParameters != null) {
    routeName =
        Uri(path: routeName, queryParameters: queryParameters).toString();
  }

  await NyNavigator.instance.router
      .navigate(routeName,
          args: nyArgument,
          navigationType: navigationType,
          result: result,
          removeUntilPredicate: removeUntilPredicate,
          pageTransitionType: pageTransitionType,
          pageTransitionSettings: pageTransitionSettings)
      .then((v) => onPop != null ? onPop(v) : (v) {});
}