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-05-31 14:56:00 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
240a99542a2a331d0863455f2c4bb6adecabf1ad
240a9954
1 parent
ebd6bca8
WIP
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
28 deletions
example_nav2/lib/app/modules/home/controllers/home_controller.dart
example_nav2/lib/app/modules/home/views/dashboard_view.dart
example_nav2/lib/app/modules/home/views/home_view.dart
example_nav2/lib/app/modules/products/controllers/products_controller.dart
example_nav2/lib/app/routes/app_pages.dart
lib/get_navigation/src/nav2/router_outlet.dart
lib/get_navigation/src/routes/default_route.dart
example_nav2/lib/app/modules/home/controllers/home_controller.dart
View file @
240a995
import
'dart:async'
;
import
'package:get/get.dart'
;
class
HomeController
extends
GetxController
{}
class
HomeController
extends
GetxController
{
final
now
=
DateTime
.
now
().
obs
;
@override
void
onReady
()
{
super
.
onReady
();
Timer
.
periodic
(
Duration
(
seconds:
1
),
(
timer
)
{
now
.
value
=
DateTime
.
now
();
},
);
}
}
...
...
example_nav2/lib/app/modules/home/views/dashboard_view.dart
View file @
240a995
...
...
@@ -8,9 +8,17 @@ class DashboardView extends GetView<HomeController> {
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
Center
(
child:
Text
(
'DashboardView is working'
,
style:
TextStyle
(
fontSize:
20
),
child:
Obx
(
()
=>
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Text
(
'DashboardView is working'
,
style:
TextStyle
(
fontSize:
20
),
),
Text
(
'Time:
${controller.now.value.toString()}
'
)
],
),
),
),
);
...
...
example_nav2/lib/app/modules/home/views/home_view.dart
View file @
240a995
...
...
@@ -30,9 +30,9 @@ class HomeView extends GetView<HomeController> {
pickPages:
(
currentNavStack
)
{
// will take any route after home
final
res
=
currentNavStack
.
pickAfterRoute
(
Routes
.
HOME
);
print
(
'''RouterOutlet rebuild:
currentStack:
$currentNavStack
pickedStack:
$res
'''
);
// print('''RouterOutlet rebuild:
// currentStack: $currentNavStack
// pickedStack: $res''');
return
res
;
},
),
...
...
example_nav2/lib/app/modules/products/controllers/products_controller.dart
View file @
240a995
...
...
@@ -18,4 +18,10 @@ class ProductsController extends GetxController {
super
.
onReady
();
loadDemoProductsFromSomeWhere
();
}
@override
void
onClose
()
{
Get
.
printInfo
(
info:
'Products: onClose'
);
super
.
onClose
();
}
}
...
...
example_nav2/lib/app/routes/app_pages.dart
View file @
240a995
...
...
@@ -22,13 +22,8 @@ class AppPages {
GetPage
(
name:
_Paths
.
HOME
,
page:
()
=>
HomeView
(),
//TODO: don't group bindings in one place, and instead make each page use its own binding
bindings:
[
HomeBinding
(),
//These must use [Get.lazyPut] or [Get.create] because their view is created long after they are declared
ProfileBinding
(),
ProductsBinding
(),
ProductDetailsBinding
(),
],
title:
null
,
middlewares:
[
...
...
@@ -39,15 +34,18 @@ class AppPages {
name:
_Paths
.
PROFILE
,
page:
()
=>
ProfileView
(),
title:
'Profile'
,
binding:
ProfileBinding
(),
),
GetPage
(
name:
_Paths
.
PRODUCTS
,
page:
()
=>
ProductsView
(),
title:
'Products'
,
binding:
ProductsBinding
(),
children:
[
GetPage
(
name:
_Paths
.
PRODUCT_DETAILS
,
page:
()
=>
ProductDetailsView
(),
binding:
ProductDetailsBinding
(),
),
],
),
...
...
lib/get_navigation/src/nav2/router_outlet.dart
View file @
240a995
...
...
@@ -22,13 +22,15 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object>
TDelegate
?
delegate
,
required
List
<
T
>
Function
(
TDelegate
routerDelegate
)
currentNavStack
,
required
List
<
T
>
Function
(
List
<
T
>
currentNavStack
)
pickPages
,
required
Widget
Function
(
TDelegate
,
T
?
page
)
pageBuilder
,
required
Widget
Function
(
BuildContext
context
,
TDelegate
,
T
?
page
)
pageBuilder
,
})
:
this
.
builder
(
builder:
(
context
,
rDelegate
,
currentConfig
)
{
final
currentStack
=
currentNavStack
(
rDelegate
);
final
picked
=
pickPages
(
currentStack
);
if
(
picked
.
length
==
0
)
return
pageBuilder
(
rDelegate
,
null
);
return
pageBuilder
(
rDelegate
,
picked
.
last
);
if
(
picked
.
length
==
0
)
return
pageBuilder
(
context
,
rDelegate
,
null
);
return
pageBuilder
(
context
,
rDelegate
,
picked
.
last
);
},
delegate:
delegate
,
);
...
...
@@ -84,11 +86,21 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetPage> {
Widget
Function
(
GetDelegate
delegate
)?
emptyStackPage
,
required
List
<
GetPage
>
Function
(
List
<
GetPage
>
currentNavStack
)
pickPages
,
})
:
super
(
pageBuilder:
(
rDelegate
,
page
)
=>
(
page
?.
page
()
??
emptyStackPage
?.
call
(
rDelegate
)
??
rDelegate
.
notFoundRoute
?.
page
())
??
SizedBox
.
shrink
(),
pageBuilder:
(
context
,
rDelegate
,
page
)
{
final
pageRoute
=
rDelegate
.
pageRoutes
[
page
];
if
(
pageRoute
!=
null
)
{
return
pageRoute
.
buildPage
(
context
,
pageRoute
.
animation
,
pageRoute
.
secondaryAnimation
,
);
}
/// improve this logic abit
return
(
emptyStackPage
?.
call
(
rDelegate
)
??
rDelegate
.
notFoundRoute
?.
page
())
??
SizedBox
.
shrink
();
},
currentNavStack:
(
routerDelegate
)
=>
routerDelegate
.
routes
,
pickPages:
pickPages
,
delegate:
Get
.
getDelegate
(),
...
...
@@ -99,11 +111,11 @@ class RouterOutletContainerMiddleWare extends GetMiddleware {
final
String
stayAt
;
RouterOutletContainerMiddleWare
(
this
.
stayAt
);
@override
RouteSettings
?
redirect
(
String
?
route
)
{
print
(
'RouterOutletContainerMiddleWare: Redirect called (
$route
)'
);
return
null
;
}
// @override
// RouteSettings? redirect(String? route) {
// print('RouterOutletContainerMiddleWare: Redirect called ($route)');
// return null;
// }
}
extension
PagesListExt
on
List
<
GetPage
>
{
...
...
lib/get_navigation/src/routes/default_route.dart
View file @
240a995
...
...
@@ -108,9 +108,9 @@ class GetPageRoute<T> extends PageRoute<T> {
@override
Widget
buildPage
(
BuildContext
context
,
Animation
<
double
>
animation
,
Animation
<
double
>
secondaryAnimation
,
BuildContext
?
context
,
Animation
<
double
>?
animation
,
Animation
<
double
>?
secondaryAnimation
,
)
{
// Get.reference = settings.name ?? routeName;
Get
.
reference
=
reference
;
...
...
Please
register
or
login
to post a comment