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-07-17 10:43:59 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fb7728fec56af42e684decb99f1cce8130f746ad
fb7728fe
1 parent
195b46f8
minor improvements and bug fixes
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
138 additions
and
100 deletions
example_nav2/lib/app/modules/login/controllers/login_controller.dart
example_nav2/lib/app/modules/login/views/login_view.dart
example_nav2/lib/app/modules/product_details/controllers/product_details_controller.dart
example_nav2/lib/app/modules/profile/views/profile_view.dart
example_nav2/lib/app/modules/root/views/root_view.dart
example_nav2/lib/app/routes/app_pages.dart
example_nav2/lib/main.dart
lib/get_core/src/get_interface.dart
lib/get_navigation/src/extension_navigation.dart
lib/get_navigation/src/nav2/get_information_parser.dart
lib/get_navigation/src/nav2/get_router_delegate.dart
lib/get_navigation/src/nav2/router_outlet.dart
lib/get_navigation/src/root/get_cupertino_app.dart
lib/get_navigation/src/root/get_material_app.dart
lib/get_navigation/src/root/parse_route.dart
lib/get_navigation/src/root/root_controller.dart
example_nav2/lib/app/modules/login/controllers/login_controller.dart
View file @
fb7728f
import
'package:get/get.dart'
;
class
LoginController
extends
GetxController
{
//TODO: Implement LoginController
final
count
=
0
.
obs
;
@override
void
onInit
()
{
super
.
onInit
();
}
@override
void
onReady
()
{
super
.
onReady
();
}
@override
void
onClose
()
{}
void
increment
()
=>
count
.
value
++;
}
class
LoginController
extends
GetxController
{}
...
...
example_nav2/lib/app/modules/login/views/login_view.dart
View file @
fb7728f
...
...
@@ -33,7 +33,7 @@ class LoginView extends GetView<LoginController> {
AuthService
.
to
.
login
();
final
thenTo
=
Get
.
rootDelegate
.
currentConfiguration
!
.
currentPage
!.
parameter
?[
'then'
];
Get
.
rootDelegate
.
to
Named
(
thenTo
??
Routes
.
HOME
);
Get
.
rootDelegate
.
off
Named
(
thenTo
??
Routes
.
HOME
);
},
),
],
...
...
example_nav2/lib/app/modules/product_details/controllers/product_details_controller.dart
View file @
fb7728f
...
...
@@ -4,4 +4,15 @@ class ProductDetailsController extends GetxController {
final
String
productId
;
ProductDetailsController
(
this
.
productId
);
@override
void
onInit
()
{
super
.
onInit
();
Get
.
log
(
'ProductDetailsController created with id:
$productId
'
);
}
@override
void
onClose
()
{
Get
.
log
(
'ProductDetailsController close with id:
$productId
'
);
super
.
onClose
();
}
}
...
...
example_nav2/lib/app/modules/profile/views/profile_view.dart
View file @
fb7728f
...
...
@@ -10,9 +10,23 @@ class ProfileView extends GetView<ProfileController> {
return
Scaffold
(
backgroundColor:
Colors
.
amber
,
body:
Center
(
child:
Text
(
'ProfileView is working'
,
style:
TextStyle
(
fontSize:
20
),
child:
Column
(
children:
[
Text
(
'ProfileView is working'
,
style:
TextStyle
(
fontSize:
20
),
),
MaterialButton
(
child:
Text
(
'Show a test dialog'
),
onPressed:
()
{
//shows a dialog
Get
.
defaultDialog
(
title:
'Test Dialog !!'
,
barrierDismissible:
true
,
);
},
)
],
),
),
);
...
...
example_nav2/lib/app/modules/root/views/root_view.dart
View file @
fb7728f
...
...
@@ -18,7 +18,7 @@ class RootView extends GetView<RootController> {
centerTitle:
true
,
),
body:
GetRouterOutlet
(
name:
'
/
'
,
name:
'
rootView
'
,
emptyPage:
(
delegate
)
=>
Get
.
routeTree
.
matchRoute
(
Routes
.
HOME
).
route
!,
pickPages:
(
currentNavStack
)
{
...
...
example_nav2/lib/app/routes/app_pages.dart
View file @
fb7728f
...
...
@@ -31,18 +31,21 @@ class AppPages {
page:
()
=>
RootView
(),
binding:
RootBinding
(),
participatesInRootNavigator:
true
,
preventDuplicates:
true
,
children:
[
GetPage
(
middlewares:
[
//only enter this route when not authed
EnsureNotAuthedMiddleware
(),
],
participatesInRootNavigator:
false
,
name:
_Paths
.
LOGIN
,
page:
()
=>
LoginView
(),
binding:
LoginBinding
(),
),
GetPage
(
participatesInRootNavigator:
true
,
participatesInRootNavigator:
false
,
preventDuplicates:
true
,
name:
_Paths
.
HOME
,
page:
()
=>
HomeView
(),
bindings:
[
...
...
example_nav2/lib/main.dart
View file @
fb7728f
...
...
@@ -16,14 +16,14 @@ void main() {
},
),
getPages:
AppPages
.
routes
,
routeInformationParser:
GetInformationParser
(
// initialRoute: Routes.HOME,
),
routerDelegate:
GetDelegate
(
backButtonPopMode:
PopMode
.
History
,
preventDuplicateHandlingMode:
PreventDuplicateHandlingMode
.
ReorderRoutes
,
),
// routeInformationParser: GetInformationParser(
// // initialRoute: Routes.HOME,
// ),
// routerDelegate: GetDelegate(
// backButtonPopMode: PopMode.History,
// preventDuplicateHandlingMode:
// PreventDuplicateHandlingMode.ReorderRoutes,
// ),
),
);
}
...
...
lib/get_core/src/get_interface.dart
View file @
fb7728f
...
...
@@ -8,6 +8,7 @@ import 'smart_management.dart';
abstract
class
GetInterface
{
SmartManagement
smartManagement
=
SmartManagement
.
full
;
RouterDelegate
?
routerDelegate
;
RouteInformationParser
?
routeInformationParser
;
String
?
reference
;
bool
isLogEnable
=
true
;
LogWriterCallback
log
=
defaultLogWriterCallback
;
...
...
lib/get_navigation/src/extension_navigation.dart
View file @
fb7728f
...
...
@@ -1016,7 +1016,12 @@ you can only use widgets and widget functions here''';
}
GlobalKey
<
NavigatorState
>?
nestedKey
(
dynamic
key
)
{
keys
.
putIfAbsent
(
key
,
()
=>
GlobalKey
<
NavigatorState
>());
keys
.
putIfAbsent
(
key
,
()
=>
GlobalKey
<
NavigatorState
>(
debugLabel:
'Getx nested key:
${key.toString()}
'
,
),
);
return
keys
[
key
];
}
...
...
@@ -1207,9 +1212,7 @@ extension NavTwoExt on GetInterface {
/// Casts the stored router delegate to a desired type
TDelegate
?
delegate
<
TDelegate
extends
RouterDelegate
<
TPage
>,
TPage
>()
=>
_routerDelegate
as
TDelegate
?;
static
GetDelegate
?
_routerDelegate
;
routerDelegate
as
TDelegate
?;
// // ignore: use_setters_to_change_properties
// void setDefaultDelegate(RouterDelegate? delegate) {
...
...
@@ -1218,31 +1221,39 @@ extension NavTwoExt on GetInterface {
// GetDelegate? getDelegate() => delegate<GetDelegate, GetNavConfig>();
static
GetInformationParser
?
_informationParser
;
GetInformationParser
createInformationParser
({
String
initialRoute
=
'/'
})
{
return
_informationParser
??=
GetInformationParser
(
initialRoute:
initialRoute
);
if
(
routeInformationParser
==
null
)
{
return
routeInformationParser
=
GetInformationParser
(
initialRoute:
initialRoute
,
);
}
else
{
return
routerDelegate
as
GetInformationParser
;
}
}
// static GetDelegate? _delegate;
GetDelegate
get
rootDelegate
=>
createDelegate
();
GetDelegate
createDelegate
(
{
GetPage
<
dynamic
>?
notFoundRoute
,
List
<
NavigatorObserver
>?
navigatorObservers
,
TransitionDelegate
<
dynamic
>?
transitionDelegate
,
PopMode
backButtonPopMode
=
PopMode
.
History
,
PreventDuplicateHandlingMode
preventDuplicateHandlingMode
=
PreventDuplicateHandlingMode
.
ReorderRoutes
})
{
return
_routerDelegate
??=
GetDelegate
(
notFoundRoute:
notFoundRoute
,
navigatorObservers:
navigatorObservers
,
transitionDelegate:
transitionDelegate
,
backButtonPopMode:
backButtonPopMode
,
preventDuplicateHandlingMode:
preventDuplicateHandlingMode
,
);
GetDelegate
createDelegate
({
GetPage
<
dynamic
>?
notFoundRoute
,
List
<
NavigatorObserver
>?
navigatorObservers
,
TransitionDelegate
<
dynamic
>?
transitionDelegate
,
PopMode
backButtonPopMode
=
PopMode
.
History
,
PreventDuplicateHandlingMode
preventDuplicateHandlingMode
=
PreventDuplicateHandlingMode
.
ReorderRoutes
,
})
{
if
(
routerDelegate
==
null
)
{
return
routerDelegate
=
GetDelegate
(
notFoundRoute:
notFoundRoute
,
navigatorObservers:
navigatorObservers
,
transitionDelegate:
transitionDelegate
,
backButtonPopMode:
backButtonPopMode
,
preventDuplicateHandlingMode:
preventDuplicateHandlingMode
,
);
}
else
{
return
routerDelegate
as
GetDelegate
;
}
}
}
...
...
lib/get_navigation/src/nav2/get_information_parser.dart
View file @
fb7728f
...
...
@@ -7,7 +7,9 @@ class GetInformationParser extends RouteInformationParser<GetNavConfig> {
GetInformationParser
({
this
.
initialRoute
=
'/'
,
});
})
{
Get
.
log
(
'GetInformationParser is created !'
);
}
@override
SynchronousFuture
<
GetNavConfig
>
parseRouteInformation
(
RouteInformation
routeInformation
,
...
...
lib/get_navigation/src/nav2/get_router_delegate.dart
View file @
fb7728f
...
...
@@ -46,7 +46,7 @@ enum PreventDuplicateHandlingMode {
ReorderRoutes
}
class
GetDelegate
<
T
>
extends
RouterDelegate
<
GetNavConfig
>
class
GetDelegate
extends
RouterDelegate
<
GetNavConfig
>
with
ListenableMixin
,
ListNotifierMixin
{
final
List
<
GetNavConfig
>
history
=
<
GetNavConfig
>[];
final
PopMode
backButtonPopMode
;
...
...
@@ -68,7 +68,9 @@ class GetDelegate<T> extends RouterDelegate<GetNavConfig>
this
.
backButtonPopMode
=
PopMode
.
History
,
this
.
preventDuplicateHandlingMode
=
PreventDuplicateHandlingMode
.
ReorderRoutes
,
});
})
{
Get
.
log
(
'GetDelegate is created !'
);
}
GetNavConfig
?
runMiddleware
(
GetNavConfig
config
)
{
final
middlewares
=
config
.
currentTreeBranch
.
last
.
middlewares
??
[];
...
...
@@ -93,7 +95,7 @@ class GetDelegate<T> extends RouterDelegate<GetNavConfig>
}
GetNavConfig
?
_unsafeHistoryRemoveAt
(
int
index
)
{
if
(
index
==
history
.
length
-
1
)
{
if
(
index
==
history
.
length
-
1
&&
history
.
length
>
1
)
{
//removing WILL update the current route
final
toCheck
=
history
[
history
.
length
-
2
];
final
resMiddleware
=
runMiddleware
(
toCheck
);
...
...
@@ -290,8 +292,9 @@ class GetDelegate<T> extends RouterDelegate<GetNavConfig>
@override
Future
<
void
>
setInitialRoutePath
(
GetNavConfig
configuration
)
async
{
_unsafeHistoryClear
();
_resultCompleter
.
clear
();
//no need to clear history with Reorder route strategy
// _unsafeHistoryClear();
// _resultCompleter.clear();
await
pushHistory
(
configuration
);
}
...
...
@@ -318,6 +321,11 @@ class GetDelegate<T> extends RouterDelegate<GetNavConfig>
);
}
Future
<
T
?>
offNamed
<
T
>(
String
fullRoute
)
async
{
await
popHistory
();
return
await
toNamed
(
fullRoute
);
}
/// Removes routes according to [PopMode]
/// until it reaches the specifc [fullRoute],
/// DOES NOT remove the [fullRoute]
...
...
lib/get_navigation/src/nav2/router_outlet.dart
View file @
fb7728f
...
...
@@ -25,17 +25,17 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object>
required
Widget
Function
(
BuildContext
context
,
TDelegate
,
GetPage
?
page
,
List
<
GetPage
>
?
page
,
)
pageBuilder
,
})
:
this
.
builder
(
builder:
(
context
,
rDelegate
,
currentConfig
)
{
final
picked
=
currentConfig
==
null
?
<
GetPage
>[]
:
pickPages
(
currentConfig
);
if
(
picked
.
length
==
0
)
{
return
pageBuilder
(
context
,
rDelegate
,
null
);
var
picked
=
currentConfig
==
null
?
null
:
pickPages
(
currentConfig
);
if
(
picked
?.
length
==
0
)
{
picked
=
null
;
}
return
pageBuilder
(
context
,
rDelegate
,
picked
.
last
);
return
pageBuilder
(
context
,
rDelegate
,
picked
);
},
delegate:
delegate
,
);
...
...
@@ -101,15 +101,25 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> {
(
emptyPage
==
null
&&
emptyWidget
!=
null
),
'Either use emptyPage or emptyWidget'
),
super
(
pageBuilder:
(
context
,
rDelegate
,
page
)
{
var
pageRes
=
page
??
emptyPage
?.
call
(
rDelegate
);
if
(
pageRes
!=
null
)
{
pageBuilder:
(
context
,
rDelegate
,
pages
)
{
final
pageRes
=
(
pages
??
<
GetPage
<
dynamic
>?>[
emptyPage
?.
call
(
rDelegate
)])
.
whereType
<
GetPage
<
dynamic
>>()
.
toList
();
final
badPages
=
pageRes
.
where
(
(
element
)
=>
element
.
participatesInRootNavigator
==
true
);
if
(
badPages
.
length
>
0
)
{
throw
"""Pages in a router outlet shouldn't participate in the root navigator
$badPages
"""
;
}
if
(
pageRes
.
length
>
0
)
{
return
GetNavigator
(
onPopPage:
onPopPage
??
(
a
,
c
)
{
return
true
;
},
pages:
[
pageRes
]
,
pages:
pageRes
,
name:
name
,
);
}
...
...
lib/get_navigation/src/root/get_cupertino_app.dart
View file @
fb7728f
...
...
@@ -163,11 +163,13 @@ class GetCupertinoApp extends StatelessWidget {
this
.
defaultGlobalState
,
this
.
getPages
,
this
.
unknownRoute
,
})
:
routerDelegate
=
routerDelegate
??
Get
.
createDelegate
(),
routeInformationParser
=
routeInformationParser
??
Get
.
createInformationParser
(
initialRoute:
getPages
?.
first
.
name
??
'/'
,
),
})
:
routerDelegate
=
routerDelegate
??=
Get
.
createDelegate
(
notFoundRoute:
unknownRoute
,
),
routeInformationParser
=
routeInformationParser
??=
Get
.
createInformationParser
(
initialRoute:
getPages
?.
first
.
name
??
'/'
,
),
navigatorObservers
=
null
,
navigatorKey
=
null
,
onGenerateRoute
=
null
,
...
...
@@ -176,7 +178,10 @@ class GetCupertinoApp extends StatelessWidget {
onUnknownRoute
=
null
,
routes
=
null
,
initialRoute
=
null
,
super
(
key:
key
);
super
(
key:
key
)
{
Get
.
routerDelegate
=
routerDelegate
;
Get
.
routeInformationParser
=
routeInformationParser
;
}
Route
<
dynamic
>
generator
(
RouteSettings
settings
)
{
return
PageRedirect
(
settings:
settings
,
unknownRoute:
unknownRoute
).
page
();
...
...
lib/get_navigation/src/root/get_material_app.dart
View file @
fb7728f
...
...
@@ -173,11 +173,13 @@ class GetMaterialApp extends StatelessWidget {
this
.
defaultGlobalState
,
this
.
getPages
,
this
.
unknownRoute
,
})
:
routerDelegate
=
routerDelegate
??
Get
.
createDelegate
(),
routeInformationParser
=
routeInformationParser
??
Get
.
createInformationParser
(
initialRoute:
getPages
?.
first
.
name
??
'/'
,
),
})
:
routerDelegate
=
routerDelegate
??=
Get
.
createDelegate
(
notFoundRoute:
unknownRoute
,
),
routeInformationParser
=
routeInformationParser
??=
Get
.
createInformationParser
(
initialRoute:
getPages
?.
first
.
name
??
'/'
,
),
navigatorObservers
=
null
,
navigatorKey
=
null
,
onGenerateRoute
=
null
,
...
...
@@ -186,7 +188,10 @@ class GetMaterialApp extends StatelessWidget {
onUnknownRoute
=
null
,
routes
=
null
,
initialRoute
=
null
,
super
(
key:
key
);
super
(
key:
key
)
{
Get
.
routerDelegate
=
routerDelegate
;
Get
.
routeInformationParser
=
routeInformationParser
;
}
Route
<
dynamic
>
generator
(
RouteSettings
settings
)
{
return
PageRedirect
(
settings:
settings
,
unknownRoute:
unknownRoute
).
page
();
...
...
lib/get_navigation/src/root/parse_route.dart
View file @
fb7728f
...
...
@@ -128,24 +128,9 @@ class ParseRouteTree {
/// Change the Path for a [GetPage]
GetPage
_addChild
(
GetPage
origin
,
String
parentPath
,
List
<
GetMiddleware
>
middlewares
)
=>
GetPage
(
name:
(
parentPath
+
origin
.
name
).
replaceAll
(
r'//'
,
'/'
),
page:
origin
.
page
,
title:
origin
.
title
,
alignment:
origin
.
alignment
,
transition:
origin
.
transition
,
binding:
origin
.
binding
,
bindings:
origin
.
bindings
,
curve:
origin
.
curve
,
customTransition:
origin
.
customTransition
,
fullscreenDialog:
origin
.
fullscreenDialog
,
maintainState:
origin
.
maintainState
,
opaque:
origin
.
opaque
,
parameter:
origin
.
parameter
,
popGesture:
origin
.
popGesture
,
preventDuplicates:
origin
.
preventDuplicates
,
transitionDuration:
origin
.
transitionDuration
,
origin
.
copy
(
middlewares:
middlewares
,
name:
(
parentPath
+
origin
.
name
).
replaceAll
(
r'//'
,
'/'
),
);
GetPage
?
_findRoute
(
String
name
)
{
...
...
lib/get_navigation/src/root/root_controller.dart
View file @
fb7728f
...
...
@@ -29,7 +29,7 @@ class GetMaterialController extends GetxController {
CustomTransition
?
customTransition
;
GlobalKey
<
NavigatorState
>
key
=
GlobalKey
<
NavigatorState
>(
);
var
key
=
GlobalKey
<
NavigatorState
>(
debugLabel:
'Key Created by default'
);
Map
<
dynamic
,
GlobalKey
<
NavigatorState
>>
keys
=
{};
...
...
Please
register
or
login
to post a comment