Showing
6 changed files
with
35 additions
and
31 deletions
@@ -23,6 +23,8 @@ class HomeView extends GetView<HomeController> { | @@ -23,6 +23,8 @@ class HomeView extends GetView<HomeController> { | ||
23 | body: GetRouterOutlet( | 23 | body: GetRouterOutlet( |
24 | emptyPage: (delegate) => DashboardView(), | 24 | emptyPage: (delegate) => DashboardView(), |
25 | pickPages: (currentNavStack) { | 25 | pickPages: (currentNavStack) { |
26 | + print('Home RouterOutlet: $currentNavStack'); | ||
27 | + | ||
26 | // will take any route after home | 28 | // will take any route after home |
27 | final res = | 29 | final res = |
28 | currentNavStack.currentTreeBranch.pickAfterRoute(Routes.HOME); | 30 | currentNavStack.currentTreeBranch.pickAfterRoute(Routes.HOME); |
@@ -35,8 +35,6 @@ class GetInformationParser extends RouteInformationParser<GetNavConfig> { | @@ -35,8 +35,6 @@ class GetInformationParser extends RouteInformationParser<GetNavConfig> { | ||
35 | 35 | ||
36 | @override | 36 | @override |
37 | RouteInformation restoreRouteInformation(GetNavConfig config) { | 37 | RouteInformation restoreRouteInformation(GetNavConfig config) { |
38 | - print('restore $config'); | ||
39 | - | ||
40 | return RouteInformation( | 38 | return RouteInformation( |
41 | location: config.location, | 39 | location: config.location, |
42 | state: config.state, | 40 | state: config.state, |
@@ -31,8 +31,5 @@ class GetNavConfig extends RouteInformation { | @@ -31,8 +31,5 @@ class GetNavConfig extends RouteInformation { | ||
31 | 31 | ||
32 | @override | 32 | @override |
33 | String toString() => ''' | 33 | String toString() => ''' |
34 | - ======GetNavConfig===== | ||
35 | - currentTreeBranch: $currentTreeBranch | ||
36 | - currentPage: $currentPage | ||
37 | - ======GetNavConfig====='''; | 34 | +======GetNavConfig=====\ncurrentTreeBranch: $currentTreeBranch\ncurrentPage: $currentPage\n======GetNavConfig====='''; |
38 | } | 35 | } |
@@ -46,7 +46,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -46,7 +46,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
46 | final List<GetNavConfig> history = <GetNavConfig>[]; | 46 | final List<GetNavConfig> history = <GetNavConfig>[]; |
47 | final PopMode backButtonPopMode; | 47 | final PopMode backButtonPopMode; |
48 | final PreventDuplicateHandlingMode preventDuplicateHandlingMode; | 48 | final PreventDuplicateHandlingMode preventDuplicateHandlingMode; |
49 | - final pageRoutes = <String, GetPageRoute>{}; | ||
50 | 49 | ||
51 | GetPage? notFoundRoute; | 50 | GetPage? notFoundRoute; |
52 | 51 | ||
@@ -82,7 +81,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -82,7 +81,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
82 | 81 | ||
83 | void _removeHistoryEntry(GetNavConfig entry) { | 82 | void _removeHistoryEntry(GetNavConfig entry) { |
84 | history.remove(entry); | 83 | history.remove(entry); |
85 | - pageRoutes.remove(entry.location); | ||
86 | final lastCompleter = _resultCompleter.remove(entry); | 84 | final lastCompleter = _resultCompleter.remove(entry); |
87 | lastCompleter?.complete(entry); | 85 | lastCompleter?.complete(entry); |
88 | } | 86 | } |
@@ -92,7 +90,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -92,7 +90,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
92 | if (history.any((element) => element.location == config.location)) { | 90 | if (history.any((element) => element.location == config.location)) { |
93 | switch (preventDuplicateHandlingMode) { | 91 | switch (preventDuplicateHandlingMode) { |
94 | case PreventDuplicateHandlingMode.PopUntilOriginalRoute: | 92 | case PreventDuplicateHandlingMode.PopUntilOriginalRoute: |
95 | - until(config.location!, popMode: PopMode.History); | 93 | + until(config.location!, popMode: PopMode.Page); |
96 | return; | 94 | return; |
97 | case PreventDuplicateHandlingMode.DoNothing: | 95 | case PreventDuplicateHandlingMode.DoNothing: |
98 | default: | 96 | default: |
@@ -101,8 +99,11 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -101,8 +99,11 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
101 | } | 99 | } |
102 | } | 100 | } |
103 | history.add(config); | 101 | history.add(config); |
104 | - pageRoutes[config.location!] = | ||
105 | - PageRedirect(config.currentPage!, _notFound()).page(); | 102 | + } |
103 | + | ||
104 | + GetPageRoute getPageRoute(RouteSettings? settings) { | ||
105 | + return PageRedirect(settings ?? RouteSettings(name: '/404'), _notFound()) | ||
106 | + .page(); | ||
106 | } | 107 | } |
107 | 108 | ||
108 | GetNavConfig? _popHistory() { | 109 | GetNavConfig? _popHistory() { |
@@ -112,7 +113,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -112,7 +113,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
112 | 113 | ||
113 | GetNavConfig _doPopHistory() { | 114 | GetNavConfig _doPopHistory() { |
114 | final res = history.removeLast(); | 115 | final res = history.removeLast(); |
115 | - pageRoutes.remove(res.location); | ||
116 | return res; | 116 | return res; |
117 | } | 117 | } |
118 | 118 | ||
@@ -190,6 +190,16 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -190,6 +190,16 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
190 | return SynchronousFuture(_canPopPage()); | 190 | return SynchronousFuture(_canPopPage()); |
191 | } | 191 | } |
192 | 192 | ||
193 | + bool _canPop(PopMode mode) { | ||
194 | + switch (mode) { | ||
195 | + case PopMode.History: | ||
196 | + return _canPopHistory(); | ||
197 | + case PopMode.Page: | ||
198 | + default: | ||
199 | + return _canPopPage(); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
193 | /// gets the visual pages from the current history entry | 203 | /// gets the visual pages from the current history entry |
194 | /// | 204 | /// |
195 | /// visual pages must have the [RouterOutletContainerMiddleWare] middleware | 205 | /// visual pages must have the [RouterOutletContainerMiddleWare] middleware |
@@ -225,7 +235,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -225,7 +235,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
225 | @override | 235 | @override |
226 | Future<void> setInitialRoutePath(GetNavConfig configuration) async { | 236 | Future<void> setInitialRoutePath(GetNavConfig configuration) async { |
227 | history.clear(); | 237 | history.clear(); |
228 | - pageRoutes.clear(); | ||
229 | _resultCompleter.clear(); | 238 | _resultCompleter.clear(); |
230 | await pushHistory(configuration); | 239 | await pushHistory(configuration); |
231 | } | 240 | } |
@@ -242,11 +251,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -242,11 +251,6 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
242 | return route; | 251 | return route; |
243 | } | 252 | } |
244 | 253 | ||
245 | - GetPageRoute? get currentRoute { | ||
246 | - final curPage = currentConfiguration?.currentPage; | ||
247 | - return curPage == null ? null : pageRoutes[curPage]; | ||
248 | - } | ||
249 | - | ||
250 | Future<T?> toNamed<T>(String fullRoute) { | 254 | Future<T?> toNamed<T>(String fullRoute) { |
251 | final decoder = Get.routeTree.matchRoute(fullRoute); | 255 | final decoder = Get.routeTree.matchRoute(fullRoute); |
252 | return pushHistory<T>( | 256 | return pushHistory<T>( |
@@ -263,12 +267,12 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -263,12 +267,12 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
263 | /// DOES NOT remove the [fullRoute] | 267 | /// DOES NOT remove the [fullRoute] |
264 | void until( | 268 | void until( |
265 | String fullRoute, { | 269 | String fullRoute, { |
266 | - PopMode popMode = PopMode.History, | 270 | + PopMode popMode = PopMode.Page, |
267 | }) { | 271 | }) { |
268 | // remove history or page entries until you meet route | 272 | // remove history or page entries until you meet route |
269 | - final currentEntry = currentConfiguration; | ||
270 | - var iterator = currentEntry; | ||
271 | - while (history.length > 0 && | 273 | + |
274 | + var iterator = currentConfiguration; | ||
275 | + while (_canPop(popMode) && | ||
272 | iterator != null && | 276 | iterator != null && |
273 | iterator.location != fullRoute) { | 277 | iterator.location != fullRoute) { |
274 | _pop(popMode); | 278 | _pop(popMode); |
@@ -304,7 +308,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -304,7 +308,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
304 | @override | 308 | @override |
305 | Future<bool> popRoute({ | 309 | Future<bool> popRoute({ |
306 | Object? result, | 310 | Object? result, |
307 | - PopMode popMode = PopMode.History, | 311 | + PopMode popMode = PopMode.Page, |
308 | }) async { | 312 | }) async { |
309 | //Returning false will cause the entire app to be popped. | 313 | //Returning false will cause the entire app to be popped. |
310 | final wasPopup = await handlePopupRoutes(result: result); | 314 | final wasPopup = await handlePopupRoutes(result: result); |
@@ -50,6 +50,7 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | @@ -50,6 +50,7 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | ||
50 | @override | 50 | @override |
51 | void initState() { | 51 | void initState() { |
52 | super.initState(); | 52 | super.initState(); |
53 | + _getCurrentRoute(); | ||
53 | delegate.addListener(onRouterDelegateChanged); | 54 | delegate.addListener(onRouterDelegateChanged); |
54 | } | 55 | } |
55 | 56 | ||
@@ -60,11 +61,12 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | @@ -60,11 +61,12 @@ class _RouterOutletState<TDelegate extends RouterDelegate<T>, T extends Object> | ||
60 | } | 61 | } |
61 | 62 | ||
62 | T? currentRoute; | 63 | T? currentRoute; |
64 | + void _getCurrentRoute() { | ||
65 | + currentRoute = delegate.currentConfiguration; | ||
66 | + } | ||
63 | 67 | ||
64 | void onRouterDelegateChanged() { | 68 | void onRouterDelegateChanged() { |
65 | - setState(() { | ||
66 | - currentRoute = delegate.currentConfiguration; | ||
67 | - }); | 69 | + setState(_getCurrentRoute); |
68 | } | 70 | } |
69 | 71 | ||
70 | @override | 72 | @override |
@@ -92,8 +94,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> { | @@ -92,8 +94,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> { | ||
92 | required List<GetPage> Function(GetNavConfig currentNavStack) pickPages, | 94 | required List<GetPage> Function(GetNavConfig currentNavStack) pickPages, |
93 | }) : super( | 95 | }) : super( |
94 | pageBuilder: (context, rDelegate, page) { | 96 | pageBuilder: (context, rDelegate, page) { |
95 | - final pageRoute = rDelegate.pageRoutes[page?.name]; | ||
96 | - if (pageRoute != null) { | 97 | + final pageRoute = rDelegate.getPageRoute(page); |
98 | + if (page != null) { | ||
97 | //TODO: transitions go here ! | 99 | //TODO: transitions go here ! |
98 | return pageRoute.buildPage( | 100 | return pageRoute.buildPage( |
99 | context, | 101 | context, |
@@ -104,8 +106,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> { | @@ -104,8 +106,8 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetNavConfig> { | ||
104 | 106 | ||
105 | /// TODO: improve this logic abit | 107 | /// TODO: improve this logic abit |
106 | return (emptyPage?.call(rDelegate) ?? | 108 | return (emptyPage?.call(rDelegate) ?? |
107 | - rDelegate.notFoundRoute?.page()) ?? | ||
108 | - SizedBox.shrink(); | 109 | + pageRoute.page?.call() ?? |
110 | + SizedBox.shrink()); | ||
109 | }, | 111 | }, |
110 | pickPages: pickPages, | 112 | pickPages: pickPages, |
111 | delegate: Get.getDelegate(), | 113 | delegate: Get.getDelegate(), |
@@ -53,6 +53,7 @@ class ParseRouteTree { | @@ -53,6 +53,7 @@ class ParseRouteTree { | ||
53 | .map( | 53 | .map( |
54 | (e) => e.value!.copy( | 54 | (e) => e.value!.copy( |
55 | parameter: params, | 55 | parameter: params, |
56 | + name: e.key, | ||
56 | ), | 57 | ), |
57 | ) | 58 | ) |
58 | .toList(); | 59 | .toList(); |
@@ -110,7 +111,7 @@ class ParseRouteTree { | @@ -110,7 +111,7 @@ class ParseRouteTree { | ||
110 | GetPage _addChild( | 111 | GetPage _addChild( |
111 | GetPage origin, String parentPath, List<GetMiddleware> middlewares) => | 112 | GetPage origin, String parentPath, List<GetMiddleware> middlewares) => |
112 | GetPage( | 113 | GetPage( |
113 | - name: parentPath + origin.name, | 114 | + name: (parentPath + origin.name).replaceAll(r'//', '/'), |
114 | page: origin.page, | 115 | page: origin.page, |
115 | title: origin.title, | 116 | title: origin.title, |
116 | alignment: origin.alignment, | 117 | alignment: origin.alignment, |
-
Please register or login to post a comment