Skip to content

Commit

Permalink
Merge 126382a into 625c853
Browse files Browse the repository at this point in the history
  • Loading branch information
marcobraghim committed Nov 6, 2020
2 parents 625c853 + 126382a commit d416ece
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions flutter_modular/lib/src/routers/route_link.dart
Expand Up @@ -23,44 +23,30 @@ class RouteLink extends IModularNavigator {
void pop<T extends Object>([T result]) => Modular.navigator.pop(result);

@override
Future<T> popAndPushNamed<T extends Object, TO extends Object>(
String routeName,
{TO result,
Object arguments}) =>
Modular.navigator.popAndPushNamed(_checkpath(routeName),
result: result, arguments: arguments);
Future<T> popAndPushNamed<T extends Object, TO extends Object>(String routeName, {TO result, Object arguments}) =>
Modular.navigator.popAndPushNamed(_checkpath(routeName), result: result, arguments: arguments);

@override
void popUntil(bool Function(Route) predicate) =>
Modular.navigator.popUntil(predicate);
void popUntil(bool Function(Route) predicate) => Modular.navigator.popUntil(predicate);

@override
Future<T> push<T extends Object>(Route<T> route) =>
Modular.navigator.push(route);
Future<T> push<T extends Object>(Route<T> route) => Modular.navigator.push(route);

@override
Future<T> pushNamed<T extends Object>(String routeName, {Object arguments}) =>
Modular.navigator.pushNamed(_checkpath(routeName), arguments: arguments);

@override
Future<T> pushNamedAndRemoveUntil<T extends Object>(
String newRouteName, bool Function(Route) predicate,
Future<T> pushNamedAndRemoveUntil<T extends Object>(String newRouteName, bool Function(Route) predicate,
{Object arguments}) =>
Modular.navigator.pushNamedAndRemoveUntil(
_checkpath(newRouteName), predicate,
arguments: arguments);
Modular.navigator.pushNamedAndRemoveUntil(_checkpath(newRouteName), predicate, arguments: arguments);
@override
Future<T> pushReplacementNamed<T extends Object, TO extends Object>(
String routeName,
{TO result,
Object arguments}) =>
Modular.navigator.pushReplacementNamed(_checkpath(routeName),
result: result, arguments: arguments);
Future<T> pushReplacementNamed<T extends Object, TO extends Object>(String routeName,
{TO result, Object arguments}) =>
Modular.navigator.pushReplacementNamed(_checkpath(routeName), result: result, arguments: arguments);

@override
Future<T> pushReplacement<T extends Object, TO extends Object>(
Route<T> newRoute,
{TO result}) =>
Future<T> pushReplacement<T extends Object, TO extends Object>(Route<T> newRoute, {TO result}) =>
Modular.navigator.pushReplacement(newRoute, result: result);

@override
Expand All @@ -69,14 +55,29 @@ class RouteLink extends IModularNavigator {
@required WidgetBuilder builder,
bool barrierDismissible = true,
}) =>
Modular.navigator.showDialog(
builder: builder,
child: child,
barrierDismissible: barrierDismissible);
Modular.navigator.showDialog(builder: builder, child: child, barrierDismissible: barrierDismissible);

String _checkpath(String routeName) {
// Add a slash to the begin of route name if haven't
routeName = routeName[0] == '/' ? routeName : '/$routeName';
var newPath = "$modulePath$routeName".replaceAll('//', '/');

// Split main path to a list
var modulePathList = modulePath.split('/');

// While the route given by user starts with backward token string
while (routeName.startsWith('/..')) {
// Remove last item from main path
modulePathList.removeLast();

// remove this 3 chars from begin of user given route
routeName = routeName.substring(3);
}

// Transform the list to string again
final modulePathComp = modulePathList.reduce((value, element) => "$value/$element");

var newPath = "$modulePathComp$routeName".replaceAll('//', '/');

return newPath;
}

Expand Down

0 comments on commit d416ece

Please sign in to comment.