Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Schaban
2020-11-28 17:25:52 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
85945773c78d4a1995563b5aeba2ce95bc62a1f2
85945773
1 parent
2e66dded
Add aprent middlwares to children
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
11 deletions
lib/get_navigation/src/root/parse_route.dart
lib/get_navigation/src/routes/route_middleware.dart
lib/get_navigation/src/root/parse_route.dart
View file @
8594577
import
'package:flutter/widgets.dart'
;
import
'package:get/get.dart'
;
import
'../routes/get_route.dart'
;
class
ParseRouteTree
{
...
...
@@ -7,7 +8,7 @@ class ParseRouteTree {
// bool _hasDefaultRoute = false;
void
addRoute
(
GetPage
route
)
{
var
path
=
route
.
name
;
if
(
path
==
Navigator
.
defaultRouteName
)
{
// if (_hasDefaultRoute) {
// throw ("Default route was already defined");
...
...
@@ -58,20 +59,26 @@ class ParseRouteTree {
return
result
;
}
final
route
Path
=
route
.
name
;
final
parent
Path
=
route
.
name
;
for
(
var
page
in
route
.
children
)
{
result
.
add
(
_changePath
(
page
,
routePath
));
// Add Parent middlewares to children
final
pageMiddlewares
=
page
.
middlewares
??
<
GetMiddleware
>[];
pageMiddlewares
.
addAll
(
route
.
middlewares
??
<
GetMiddleware
>[]);
result
.
add
(
_addChild
(
page
,
parentPath
,
pageMiddlewares
));
final
children
=
_flattenPage
(
page
);
for
(
var
child
in
children
)
{
result
.
add
(
_changePath
(
child
,
routePath
));
pageMiddlewares
.
addAll
(
child
.
middlewares
??
<
GetMiddleware
>[]);
result
.
add
(
_addChild
(
child
,
parentPath
,
pageMiddlewares
));
}
}
return
result
;
}
/// Change the Path for a [GetPage]
GetPage
_changePath
(
GetPage
origin
,
String
routePath
)
=>
GetPage
(
name:
routePath
+
origin
.
name
,
GetPage
_addChild
(
GetPage
origin
,
String
parentPath
,
List
<
GetMiddleware
>
middlewares
)
=>
GetPage
(
name:
parentPath
+
origin
.
name
,
page:
origin
.
page
,
title:
origin
.
title
,
alignment:
origin
.
alignment
,
...
...
@@ -87,7 +94,7 @@ class ParseRouteTree {
popGesture:
origin
.
popGesture
,
settings:
origin
.
settings
,
transitionDuration:
origin
.
transitionDuration
,
middlewares:
origin
.
middlewares
,
middlewares:
middlewares
,
);
_GetPageMatch
matchRoute
(
String
path
)
{
...
...
@@ -168,7 +175,9 @@ class ParseRouteTree {
var
match
=
matches
.
first
;
var
nodeToUse
=
match
.
node
;
if
(
nodeToUse
!=
null
&&
nodeToUse
.
routes
!=
null
&&
nodeToUse
.
routes
.
length
>
0
)
{
if
(
nodeToUse
!=
null
&&
nodeToUse
.
routes
!=
null
&&
nodeToUse
.
routes
.
length
>
0
)
{
var
routes
=
nodeToUse
.
routes
;
var
routeMatch
=
_GetPageMatch
(
routes
[
0
]);
...
...
@@ -226,7 +235,8 @@ class ParseRouteTree {
class
_ParseRouteTreeNodeMatch
{
_ParseRouteTreeNodeMatch
(
this
.
node
);
_ParseRouteTreeNodeMatch
.
fromMatch
(
_ParseRouteTreeNodeMatch
match
,
this
.
node
)
{
_ParseRouteTreeNodeMatch
.
fromMatch
(
_ParseRouteTreeNodeMatch
match
,
this
.
node
)
{
parameters
=
<
String
,
String
>{};
if
(
match
!=
null
)
{
parameters
.
addAll
(
match
.
parameters
);
...
...
lib/get_navigation/src/routes/route_middleware.dart
View file @
8594577
...
...
@@ -208,7 +208,11 @@ class PageRedirect {
if
(
match
.
route
.
middlewares
==
null
||
match
.
route
.
middlewares
.
isEmpty
)
{
return
false
;
}
return
runner
.
runRedirect
()
!=
null
;
final
newSettings
=
runner
.
runRedirect
();
if
(
newSettings
==
null
)
{
return
false
;
}
settings
=
newSettings
;
return
true
;
}
}
...
...
Please
register
or
login
to post a comment