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
Ahmed Fwela
2021-06-03 21:25:46 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8646dd81b642cff1b1465729493c457754759d3f
8646dd81
1 parent
1399e561
fixed handling of route creation
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
31 deletions
example_nav2/lib/app/modules/home/views/home_view.dart
lib/get_navigation/src/nav2/get_information_parser.dart
lib/get_navigation/src/nav2/get_nav_config.dart
lib/get_navigation/src/nav2/get_router_delegate.dart
lib/get_navigation/src/nav2/router_outlet.dart
lib/get_navigation/src/root/parse_route.dart
example_nav2/lib/app/modules/home/views/home_view.dart
View file @
8646dd8
...
...
@@ -23,6 +23,8 @@ class HomeView extends GetView<HomeController> {
body:
GetRouterOutlet
(
emptyPage:
(
delegate
)
=>
DashboardView
(),
pickPages:
(
currentNavStack
)
{
print
(
'Home RouterOutlet:
$currentNavStack
'
);
// will take any route after home
final
res
=
currentNavStack
.
currentTreeBranch
.
pickAfterRoute
(
Routes
.
HOME
);
...
...
lib/get_navigation/src/nav2/get_information_parser.dart
View file @
8646dd8
...
...
@@ -35,8 +35,6 @@ class GetInformationParser extends RouteInformationParser<GetNavConfig> {
@override
RouteInformation
restoreRouteInformation
(
GetNavConfig
config
)
{
print
(
'restore
$config
'
);
return
RouteInformation
(
location:
config
.
location
,
state:
config
.
state
,
...
...
lib/get_navigation/src/nav2/get_nav_config.dart
View file @
8646dd8
...
...
@@ -31,8 +31,5 @@ class GetNavConfig extends RouteInformation {
@override
String
toString
()
=>
'''
======GetNavConfig=====
currentTreeBranch:
$currentTreeBranch
currentPage:
$currentPage
======GetNavConfig====='''
;
======GetNavConfig=====
\n
currentTreeBranch:
$currentTreeBranch
\n
currentPage:
$currentPage
\n
======GetNavConfig====='''
;
}
...
...
lib/get_navigation/src/nav2/get_router_delegate.dart
View file @
8646dd8
...
...
@@ -46,7 +46,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
final
List
<
GetNavConfig
>
history
=
<
GetNavConfig
>[];
final
PopMode
backButtonPopMode
;
final
PreventDuplicateHandlingMode
preventDuplicateHandlingMode
;
final
pageRoutes
=
<
String
,
GetPageRoute
>{};
GetPage
?
notFoundRoute
;
...
...
@@ -82,7 +81,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
void
_removeHistoryEntry
(
GetNavConfig
entry
)
{
history
.
remove
(
entry
);
pageRoutes
.
remove
(
entry
.
location
);
final
lastCompleter
=
_resultCompleter
.
remove
(
entry
);
lastCompleter
?.
complete
(
entry
);
}
...
...
@@ -92,7 +90,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
if
(
history
.
any
((
element
)
=>
element
.
location
==
config
.
location
))
{
switch
(
preventDuplicateHandlingMode
)
{
case
PreventDuplicateHandlingMode
.
PopUntilOriginalRoute
:
until
(
config
.
location
!,
popMode:
PopMode
.
History
);
until
(
config
.
location
!,
popMode:
PopMode
.
Page
);
return
;
case
PreventDuplicateHandlingMode
.
DoNothing
:
default
:
...
...
@@ -101,8 +99,11 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
}
}
history
.
add
(
config
);
pageRoutes
[
config
.
location
!]
=
PageRedirect
(
config
.
currentPage
!,
_notFound
()).
page
();
}
GetPageRoute
getPageRoute
(
RouteSettings
?
settings
)
{
return
PageRedirect
(
settings
??
RouteSettings
(
name:
'/404'
),
_notFound
())
.
page
();
}
GetNavConfig
?
_popHistory
()
{
...
...
@@ -112,7 +113,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
GetNavConfig
_doPopHistory
()
{
final
res
=
history
.
removeLast
();
pageRoutes
.
remove
(
res
.
location
);
return
res
;
}
...
...
@@ -190,6 +190,16 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
return
SynchronousFuture
(
_canPopPage
());
}
bool
_canPop
(
PopMode
mode
)
{
switch
(
mode
)
{
case
PopMode
.
History
:
return
_canPopHistory
();
case
PopMode
.
Page
:
default
:
return
_canPopPage
();
}
}
/// gets the visual pages from the current history entry
///
/// visual pages must have the [RouterOutletContainerMiddleWare] middleware
...
...
@@ -225,7 +235,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
@override
Future
<
void
>
setInitialRoutePath
(
GetNavConfig
configuration
)
async
{
history
.
clear
();
pageRoutes
.
clear
();
_resultCompleter
.
clear
();
await
pushHistory
(
configuration
);
}
...
...
@@ -242,11 +251,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
return
route
;
}
GetPageRoute
?
get
currentRoute
{
final
curPage
=
currentConfiguration
?.
currentPage
;
return
curPage
==
null
?
null
:
pageRoutes
[
curPage
];
}
Future
<
T
?>
toNamed
<
T
>(
String
fullRoute
)
{
final
decoder
=
Get
.
routeTree
.
matchRoute
(
fullRoute
);
return
pushHistory
<
T
>(
...
...
@@ -263,12 +267,12 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
/// DOES NOT remove the [fullRoute]
void
until
(
String
fullRoute
,
{
PopMode
popMode
=
PopMode
.
History
,
PopMode
popMode
=
PopMode
.
Page
,
})
{
// remove history or page entries until you meet route
final
currentEntry
=
currentConfiguration
;
var
iterator
=
currentEntry
;
while
(
history
.
length
>
0
&&
var
iterator
=
currentConfiguration
;
while
(
_canPop
(
popMode
)
&&
iterator
!=
null
&&
iterator
.
location
!=
fullRoute
)
{
_pop
(
popMode
);
...
...
@@ -304,7 +308,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig>
@override
Future
<
bool
>
popRoute
({
Object
?
result
,
PopMode
popMode
=
PopMode
.
History
,
PopMode
popMode
=
PopMode
.
Page
,
})
async
{
//Returning false will cause the entire app to be popped.
final
wasPopup
=
await
handlePopupRoutes
(
result:
result
);
...
...
lib/get_navigation/src/nav2/router_outlet.dart
View file @
8646dd8
...
...
@@ -50,6 +50,7 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object>
@override
void
initState
()
{
super
.
initState
();
_getCurrentRoute
();
delegate
.
addListener
(
onRouterDelegateChanged
);
}
...
...
@@ -60,11 +61,12 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object>
}
T
?
currentRoute
;
void
_getCurrentRoute
()
{
currentRoute
=
delegate
.
currentConfiguration
;
}
void
onRouterDelegateChanged
()
{
setState
(()
{
currentRoute
=
delegate
.
currentConfiguration
;
});
setState
(
_getCurrentRoute
);
}
@override
...
...
@@ -92,8 +94,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> {
required
List
<
GetPage
>
Function
(
GetNavConfig
currentNavStack
)
pickPages
,
})
:
super
(
pageBuilder:
(
context
,
rDelegate
,
page
)
{
final
pageRoute
=
rDelegate
.
pageRoutes
[
page
?.
name
];
if
(
pageRoute
!=
null
)
{
final
pageRoute
=
rDelegate
.
getPageRoute
(
page
);
if
(
page
!=
null
)
{
//TODO: transitions go here !
return
pageRoute
.
buildPage
(
context
,
...
...
@@ -104,8 +106,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> {
/// TODO: improve this logic abit
return
(
emptyPage
?.
call
(
rDelegate
)
??
rDelegate
.
notFoundRoute
?.
page
())
??
SizedBox
.
shrink
();
pageRoute
.
page
?.
call
()
??
SizedBox
.
shrink
());
},
pickPages:
pickPages
,
delegate:
Get
.
getDelegate
(),
...
...
lib/get_navigation/src/root/parse_route.dart
View file @
8646dd8
...
...
@@ -53,6 +53,7 @@ class ParseRouteTree {
.
map
(
(
e
)
=>
e
.
value
!.
copy
(
parameter:
params
,
name:
e
.
key
,
),
)
.
toList
();
...
...
@@ -110,7 +111,7 @@ class ParseRouteTree {
GetPage
_addChild
(
GetPage
origin
,
String
parentPath
,
List
<
GetMiddleware
>
middlewares
)
=>
GetPage
(
name:
parentPath
+
origin
.
name
,
name:
(
parentPath
+
origin
.
name
).
replaceAll
(
r'//'
,
'/'
)
,
page:
origin
.
page
,
title:
origin
.
title
,
alignment:
origin
.
alignment
,
...
...
Please
register
or
login
to post a comment