navigate<T> method
Function used to navigate pages.
name
is the route name that was registered using addRoute
.
args
are optional arguments that can be passed to the next page.
To retrieve these arguments use args
method on NyRouterRoute.
navigationType
can be specified to choose from various navigation
strategies such as NavigationType.push, NavigationType.pushReplace,
NavigationType.pushAndRemoveUntil.
removeUntilPredicate
should be provided if using
NavigationType.pushAndRemoveUntil strategy.
Implementation
Future<T> navigate<T>(String name,
{NyArgument? args,
NavigationType navigationType = NavigationType.push,
dynamic result,
bool Function(Route<dynamic> route)? removeUntilPredicate,
PageTransitionType? pageTransitionType,
PageTransitionSettings? pageTransitionSettings}) async {
assert(navigationType != NavigationType.pushAndRemoveUntil ||
removeUntilPredicate != null);
Uri? uriSettingName;
try {
uriSettingName = Uri.parse(name);
} on FormatException catch (e) {
NyLogger.error(e.toString());
}
String routeName = name;
if (uriSettingName != null) {
routeName = uriSettingName.path;
}
NyQueryParameters? nyQueryParameters;
if (uriSettingName != null && uriSettingName.queryParameters.isNotEmpty) {
nyQueryParameters = NyQueryParameters(uriSettingName.queryParameters);
}
bool checkRouteNamedArg = isRouteNamedArg(routeName);
if (!checkRouteNamedArg) {
_checkAndThrowRouteNotFound(routeName, args, navigationType);
}
return await _navigate(routeName, args, navigationType, result,
removeUntilPredicate, pageTransitionType, pageTransitionSettings,
queryParameters: nyQueryParameters, originalRouteName: name)
.then((value) => value as T);
}