Showing
10 changed files
with
166 additions
and
133 deletions
@@ -9,7 +9,6 @@ abstract class GetInterface { | @@ -9,7 +9,6 @@ abstract class GetInterface { | ||
9 | SmartManagement smartManagement = SmartManagement.full; | 9 | SmartManagement smartManagement = SmartManagement.full; |
10 | RouterDelegate? routerDelegate; | 10 | RouterDelegate? routerDelegate; |
11 | RouteInformationParser? routeInformationParser; | 11 | RouteInformationParser? routeInformationParser; |
12 | - String? reference; | ||
13 | bool isLogEnable = true; | 12 | bool isLogEnable = true; |
14 | LogWriterCallback log = defaultLogWriterCallback; | 13 | LogWriterCallback log = defaultLogWriterCallback; |
15 | } | 14 | } |
@@ -32,9 +32,9 @@ extension Inst on GetInterface { | @@ -32,9 +32,9 @@ extension Inst on GetInterface { | ||
32 | GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); | 32 | GetInstance().lazyPut<S>(builder, tag: tag, fenix: fenix); |
33 | } | 33 | } |
34 | 34 | ||
35 | - void printInstanceStack() { | ||
36 | - GetInstance().printInstanceStack(); | ||
37 | - } | 35 | + // void printInstanceStack() { |
36 | + // GetInstance().printInstanceStack(); | ||
37 | + // } | ||
38 | 38 | ||
39 | /// async version of `Get.put()`. | 39 | /// async version of `Get.put()`. |
40 | /// Awaits for the resolution of the Future from `builder()`parameter and | 40 | /// Awaits for the resolution of the Future from `builder()`parameter and |
@@ -95,9 +95,14 @@ extension Inst on GetInterface { | @@ -95,9 +95,14 @@ extension Inst on GetInterface { | ||
95 | /// - [clearFactory] clears the callbacks registered by `Get.lazyPut()` | 95 | /// - [clearFactory] clears the callbacks registered by `Get.lazyPut()` |
96 | /// - [clearRouteBindings] clears Instances associated with Routes when using | 96 | /// - [clearRouteBindings] clears Instances associated with Routes when using |
97 | /// [GetMaterialApp]. | 97 | /// [GetMaterialApp]. |
98 | - bool reset({bool clearFactory = true, bool clearRouteBindings = true}) => | 98 | + bool reset( |
99 | + {@deprecated bool clearFactory = true, | ||
100 | + @deprecated bool clearRouteBindings = true}) => | ||
99 | GetInstance().reset( | 101 | GetInstance().reset( |
100 | - clearFactory: clearFactory, clearRouteBindings: clearRouteBindings); | 102 | + // ignore: deprecated_member_use_from_same_package |
103 | + clearFactory: clearFactory, | ||
104 | + // ignore: deprecated_member_use_from_same_package | ||
105 | + clearRouteBindings: clearRouteBindings); | ||
101 | 106 | ||
102 | /// Deletes the `Instance<S>`, cleaning the memory and closes any open | 107 | /// Deletes the `Instance<S>`, cleaning the memory and closes any open |
103 | /// controllers (`DisposableInterface`). | 108 | /// controllers (`DisposableInterface`). |
1 | import 'dart:async'; | 1 | import 'dart:async'; |
2 | -import 'dart:collection'; | ||
3 | 2 | ||
4 | import '../../get_core/get_core.dart'; | 3 | import '../../get_core/get_core.dart'; |
5 | - | 4 | +import '../../get_navigation/src/router_report.dart'; |
6 | import 'lifecycle.dart'; | 5 | import 'lifecycle.dart'; |
7 | 6 | ||
8 | class InstanceInfo { | 7 | class InstanceInfo { |
@@ -38,20 +37,6 @@ class GetInstance { | @@ -38,20 +37,6 @@ class GetInstance { | ||
38 | /// `Get.lazyPut()` | 37 | /// `Get.lazyPut()` |
39 | // static final Map<String, _Lazy> _factory = {}; | 38 | // static final Map<String, _Lazy> _factory = {}; |
40 | 39 | ||
41 | - /// Holds a reference to `Get.reference` when the Instance was | ||
42 | - /// created to manage the memory. | ||
43 | - static final Map<String, String?> _routesKey = {}; | ||
44 | - | ||
45 | - /// Stores the onClose() references of instances created with `Get.create()` | ||
46 | - /// using the `Get.reference`. | ||
47 | - /// Experimental feature to keep the lifecycle and memory management with | ||
48 | - /// non-singleton instances. | ||
49 | - static final Map<String?, HashSet<Function>> _routesByCreate = {}; | ||
50 | - | ||
51 | - void printInstanceStack() { | ||
52 | - Get.log(_routesKey.toString()); | ||
53 | - } | ||
54 | - | ||
55 | void injector<S>( | 40 | void injector<S>( |
56 | InjectorBuilderCallback<S> fn, { | 41 | InjectorBuilderCallback<S> fn, { |
57 | String? tag, | 42 | String? tag, |
@@ -189,64 +174,6 @@ class GetInstance { | @@ -189,64 +174,6 @@ class GetInstance { | ||
189 | ); | 174 | ); |
190 | } | 175 | } |
191 | 176 | ||
192 | - /// Clears from memory registered Instances associated with [routeName] when | ||
193 | - /// using `Get.smartManagement` as [SmartManagement.full] or | ||
194 | - /// [SmartManagement.keepFactory] | ||
195 | - /// Meant for internal usage of `GetPageRoute` and `GetDialogRoute` | ||
196 | - void removeDependencyByRoute(String routeName) { | ||
197 | - final keysToRemove = <String>[]; | ||
198 | - _routesKey.forEach((key, value) { | ||
199 | - if (value == routeName) { | ||
200 | - keysToRemove.add(key); | ||
201 | - } | ||
202 | - }); | ||
203 | - | ||
204 | - /// Removes `Get.create()` instances registered in `routeName`. | ||
205 | - if (_routesByCreate.containsKey(routeName)) { | ||
206 | - for (final onClose in _routesByCreate[routeName]!) { | ||
207 | - // assure the [DisposableInterface] instance holding a reference | ||
208 | - // to onClose() wasn't disposed. | ||
209 | - onClose(); | ||
210 | - } | ||
211 | - _routesByCreate[routeName]!.clear(); | ||
212 | - _routesByCreate.remove(routeName); | ||
213 | - } | ||
214 | - | ||
215 | - for (final element in keysToRemove) { | ||
216 | - delete(key: element); | ||
217 | - _routesKey.remove(element); | ||
218 | - } | ||
219 | - | ||
220 | - keysToRemove.clear(); | ||
221 | - } | ||
222 | - | ||
223 | - void reloadDependencyByRoute(String routeName) { | ||
224 | - final keysToRemove = <String>[]; | ||
225 | - _routesKey.forEach((key, value) { | ||
226 | - if (value == routeName) { | ||
227 | - keysToRemove.add(key); | ||
228 | - } | ||
229 | - }); | ||
230 | - | ||
231 | - /// Removes `Get.create()` instances registered in `routeName`. | ||
232 | - if (_routesByCreate.containsKey(routeName)) { | ||
233 | - for (final onClose in _routesByCreate[routeName]!) { | ||
234 | - // assure the [DisposableInterface] instance holding a reference | ||
235 | - // to onClose() wasn't disposed. | ||
236 | - onClose(); | ||
237 | - } | ||
238 | - _routesByCreate[routeName]!.clear(); | ||
239 | - _routesByCreate.remove(routeName); | ||
240 | - } | ||
241 | - | ||
242 | - for (final element in keysToRemove) { | ||
243 | - reload(key: element, closeInstance: false); | ||
244 | - //_routesKey.remove(element); | ||
245 | - } | ||
246 | - | ||
247 | - keysToRemove.clear(); | ||
248 | - } | ||
249 | - | ||
250 | /// Initializes the dependencies for a Class Instance [S] (or tag), | 177 | /// Initializes the dependencies for a Class Instance [S] (or tag), |
251 | /// If its a Controller, it starts the lifecycle process. | 178 | /// If its a Controller, it starts the lifecycle process. |
252 | /// Optionally associating the current Route to the lifetime of the instance, | 179 | /// Optionally associating the current Route to the lifetime of the instance, |
@@ -265,19 +192,13 @@ class GetInstance { | @@ -265,19 +192,13 @@ class GetInstance { | ||
265 | if (_singl[key]!.isSingleton!) { | 192 | if (_singl[key]!.isSingleton!) { |
266 | _singl[key]!.isInit = true; | 193 | _singl[key]!.isInit = true; |
267 | if (Get.smartManagement != SmartManagement.onlyBuilder) { | 194 | if (Get.smartManagement != SmartManagement.onlyBuilder) { |
268 | - _registerRouteInstance<S>(tag: name); | 195 | + RouterReportManager.reportDependencyLinkedToRoute(_getKey(S, name)); |
269 | } | 196 | } |
270 | } | 197 | } |
271 | } | 198 | } |
272 | return i; | 199 | return i; |
273 | } | 200 | } |
274 | 201 | ||
275 | - /// Links a Class instance [S] (or [tag]) to the current route. | ||
276 | - /// Requires usage of `GetMaterialApp`. | ||
277 | - void _registerRouteInstance<S>({String? tag}) { | ||
278 | - _routesKey.putIfAbsent(_getKey(S, tag), () => Get.reference); | ||
279 | - } | ||
280 | - | ||
281 | InstanceInfo getInstanceInfo<S>({String? tag}) { | 202 | InstanceInfo getInstanceInfo<S>({String? tag}) { |
282 | final build = _getDependency<S>(tag: tag); | 203 | final build = _getDependency<S>(tag: tag); |
283 | 204 | ||
@@ -313,9 +234,7 @@ class GetInstance { | @@ -313,9 +234,7 @@ class GetInstance { | ||
313 | Get.log('Instance "$S" with tag "$tag" has been initialized'); | 234 | Get.log('Instance "$S" with tag "$tag" has been initialized'); |
314 | } | 235 | } |
315 | if (!_singl[key]!.isSingleton!) { | 236 | if (!_singl[key]!.isSingleton!) { |
316 | - _routesByCreate[Get.reference] ??= HashSet<Function>(); | ||
317 | - // _routesByCreate[Get.reference]!.add(i.onDelete as Function); | ||
318 | - _routesByCreate[Get.reference]!.add(i.onDelete); | 237 | + RouterReportManager.appendRouteByCreate(i); |
319 | } | 238 | } |
320 | } | 239 | } |
321 | return i; | 240 | return i; |
@@ -370,10 +289,13 @@ class GetInstance { | @@ -370,10 +289,13 @@ class GetInstance { | ||
370 | /// [clearFactory] clears the callbacks registered by [lazyPut] | 289 | /// [clearFactory] clears the callbacks registered by [lazyPut] |
371 | /// [clearRouteBindings] clears Instances associated with routes. | 290 | /// [clearRouteBindings] clears Instances associated with routes. |
372 | /// | 291 | /// |
373 | - bool reset({bool clearFactory = true, bool clearRouteBindings = true}) { | 292 | + bool reset( |
293 | + {@deprecated bool clearFactory = true, | ||
294 | + @deprecated bool clearRouteBindings = true}) { | ||
374 | // if (clearFactory) _factory.clear(); | 295 | // if (clearFactory) _factory.clear(); |
375 | - if (clearRouteBindings) _routesKey.clear(); | ||
376 | - _singl.clear(); | 296 | + deleteAll(force: true); |
297 | + // if (clearRouteBindings) clearRouteKeys(); | ||
298 | + // _singl.clear(); | ||
377 | return true; | 299 | return true; |
378 | } | 300 | } |
379 | 301 |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | -import '../../../get_core/get_core.dart'; | ||
3 | -import '../../../get_instance/src/get_instance.dart'; | 2 | +import '../../../get.dart'; |
3 | +import '../router_report.dart'; | ||
4 | 4 | ||
5 | class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | 5 | class GetModalBottomSheetRoute<T> extends PopupRoute<T> { |
6 | GetModalBottomSheetRoute({ | 6 | GetModalBottomSheetRoute({ |
@@ -20,8 +20,9 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -20,8 +20,9 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
20 | RouteSettings? settings, | 20 | RouteSettings? settings, |
21 | this.enterBottomSheetDuration = const Duration(milliseconds: 250), | 21 | this.enterBottomSheetDuration = const Duration(milliseconds: 250), |
22 | this.exitBottomSheetDuration = const Duration(milliseconds: 200), | 22 | this.exitBottomSheetDuration = const Duration(milliseconds: 200), |
23 | - }) : name = "BOTTOMSHEET: ${builder.hashCode}", | ||
24 | - super(settings: settings); | 23 | + }) : super(settings: settings) { |
24 | + RouterReportManager.reportCurrentRoute(this); | ||
25 | + } | ||
25 | final bool? isPersistent; | 26 | final bool? isPersistent; |
26 | final WidgetBuilder? builder; | 27 | final WidgetBuilder? builder; |
27 | final ThemeData? theme; | 28 | final ThemeData? theme; |
@@ -33,7 +34,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -33,7 +34,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
33 | final Color? modalBarrierColor; | 34 | final Color? modalBarrierColor; |
34 | final bool isDismissible; | 35 | final bool isDismissible; |
35 | final bool enableDrag; | 36 | final bool enableDrag; |
36 | - final String name; | 37 | + // final String name; |
37 | final Duration enterBottomSheetDuration; | 38 | final Duration enterBottomSheetDuration; |
38 | final Duration exitBottomSheetDuration; | 39 | final Duration exitBottomSheetDuration; |
39 | // remove safearea from top | 40 | // remove safearea from top |
@@ -55,10 +56,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -55,10 +56,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
55 | 56 | ||
56 | @override | 57 | @override |
57 | void dispose() { | 58 | void dispose() { |
58 | - if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
59 | - WidgetsBinding.instance!.addPostFrameCallback( | ||
60 | - (_) => GetInstance().removeDependencyByRoute(name)); | ||
61 | - } | 59 | + RouterReportManager.reportRouteDispose(this); |
62 | super.dispose(); | 60 | super.dispose(); |
63 | } | 61 | } |
64 | 62 |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | -import '../../../get_core/get_core.dart'; | ||
3 | -import '../../../get_instance/src/get_instance.dart'; | 2 | +import '../router_report.dart'; |
4 | 3 | ||
5 | class GetDialogRoute<T> extends PopupRoute<T> { | 4 | class GetDialogRoute<T> extends PopupRoute<T> { |
6 | GetDialogRoute({ | 5 | GetDialogRoute({ |
@@ -12,13 +11,14 @@ class GetDialogRoute<T> extends PopupRoute<T> { | @@ -12,13 +11,14 @@ class GetDialogRoute<T> extends PopupRoute<T> { | ||
12 | RouteTransitionsBuilder? transitionBuilder, | 11 | RouteTransitionsBuilder? transitionBuilder, |
13 | RouteSettings? settings, | 12 | RouteSettings? settings, |
14 | }) : widget = pageBuilder, | 13 | }) : widget = pageBuilder, |
15 | - name = "DIALOG: ${pageBuilder.hashCode}", | ||
16 | _barrierDismissible = barrierDismissible, | 14 | _barrierDismissible = barrierDismissible, |
17 | _barrierLabel = barrierLabel, | 15 | _barrierLabel = barrierLabel, |
18 | _barrierColor = barrierColor, | 16 | _barrierColor = barrierColor, |
19 | _transitionDuration = transitionDuration, | 17 | _transitionDuration = transitionDuration, |
20 | _transitionBuilder = transitionBuilder, | 18 | _transitionBuilder = transitionBuilder, |
21 | - super(settings: settings); | 19 | + super(settings: settings) { |
20 | + RouterReportManager.reportCurrentRoute(this); | ||
21 | + } | ||
22 | 22 | ||
23 | final RoutePageBuilder widget; | 23 | final RoutePageBuilder widget; |
24 | 24 | ||
@@ -26,14 +26,9 @@ class GetDialogRoute<T> extends PopupRoute<T> { | @@ -26,14 +26,9 @@ class GetDialogRoute<T> extends PopupRoute<T> { | ||
26 | bool get barrierDismissible => _barrierDismissible; | 26 | bool get barrierDismissible => _barrierDismissible; |
27 | final bool _barrierDismissible; | 27 | final bool _barrierDismissible; |
28 | 28 | ||
29 | - final String name; | ||
30 | - | ||
31 | @override | 29 | @override |
32 | void dispose() { | 30 | void dispose() { |
33 | - if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
34 | - WidgetsBinding.instance!.addPostFrameCallback( | ||
35 | - (_) => GetInstance().removeDependencyByRoute(name)); | ||
36 | - } | 31 | + RouterReportManager.reportRouteDispose(this); |
37 | super.dispose(); | 32 | super.dispose(); |
38 | } | 33 | } |
39 | 34 |
@@ -235,7 +235,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -235,7 +235,7 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
235 | } | 235 | } |
236 | 236 | ||
237 | bool _canPopHistory() { | 237 | bool _canPopHistory() { |
238 | - return history.length > 0; | 238 | + return history.length > 1; |
239 | } | 239 | } |
240 | 240 | ||
241 | Future<bool> canPopHistory() { | 241 | Future<bool> canPopHistory() { |
@@ -347,8 +347,8 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | @@ -347,8 +347,8 @@ class GetDelegate extends RouterDelegate<GetNavConfig> | ||
347 | dynamic arguments, | 347 | dynamic arguments, |
348 | Map<String, String>? parameters, | 348 | Map<String, String>? parameters, |
349 | }) async { | 349 | }) async { |
350 | - await popHistory(); | ||
351 | await toNamed(page, arguments: arguments, parameters: parameters); | 350 | await toNamed(page, arguments: arguments, parameters: parameters); |
351 | + await _unsafeHistoryRemoveAt(history.length - 2); | ||
352 | } | 352 | } |
353 | 353 | ||
354 | /// Removes routes according to [PopMode] | 354 | /// Removes routes according to [PopMode] |
lib/get_navigation/src/router_report.dart
0 → 100644
1 | +import 'dart:collection'; | ||
2 | + | ||
3 | +import 'package:flutter/widgets.dart'; | ||
4 | + | ||
5 | +import '../../get.dart'; | ||
6 | + | ||
7 | +class RouterReportManager<T> { | ||
8 | + /// Holds a reference to `Get.reference` when the Instance was | ||
9 | + /// created to manage the memory. | ||
10 | + static final Map<String, Route?> _routesKey = {}; | ||
11 | + | ||
12 | + /// Stores the onClose() references of instances created with `Get.create()` | ||
13 | + /// using the `Get.reference`. | ||
14 | + /// Experimental feature to keep the lifecycle and memory management with | ||
15 | + /// non-singleton instances. | ||
16 | + static final Map<Route?, HashSet<Function>> _routesByCreate = {}; | ||
17 | + | ||
18 | + void printInstanceStack() { | ||
19 | + Get.log(_routesKey.toString()); | ||
20 | + } | ||
21 | + | ||
22 | + static Route? _current; | ||
23 | + | ||
24 | + // ignore: use_setters_to_change_properties | ||
25 | + static void reportCurrentRoute(Route newRoute) { | ||
26 | + _current = newRoute; | ||
27 | + } | ||
28 | + | ||
29 | + /// Links a Class instance [S] (or [tag]) to the current route. | ||
30 | + /// Requires usage of `GetMaterialApp`. | ||
31 | + static void reportDependencyLinkedToRoute(String depedencyKey) { | ||
32 | + _routesKey.putIfAbsent(depedencyKey, () => _current); | ||
33 | + } | ||
34 | + | ||
35 | + void clearRouteKeys() { | ||
36 | + _routesKey.clear(); | ||
37 | + } | ||
38 | + | ||
39 | + static void appendRouteByCreate(GetLifeCycleBase i) { | ||
40 | + _routesByCreate[_current] ??= HashSet<Function>(); | ||
41 | + // _routesByCreate[Get.reference]!.add(i.onDelete as Function); | ||
42 | + _routesByCreate[_current]!.add(i.onDelete); | ||
43 | + } | ||
44 | + | ||
45 | + static void reportRouteDispose(Route disposed) { | ||
46 | + if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
47 | + WidgetsBinding.instance!.addPostFrameCallback((_) { | ||
48 | + ///TODO: Is necessary this comparator? | ||
49 | + if (_current != disposed) { | ||
50 | + _removeDependencyByRoute(disposed); | ||
51 | + } | ||
52 | + }); | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + static void reportRouteWillDispose(Route disposed) { | ||
57 | + final keysToRemove = <String>[]; | ||
58 | + _routesKey.forEach((key, value) { | ||
59 | + if (value == disposed) { | ||
60 | + keysToRemove.add(key); | ||
61 | + } | ||
62 | + }); | ||
63 | + | ||
64 | + /// Removes `Get.create()` instances registered in `routeName`. | ||
65 | + if (_routesByCreate.containsKey(disposed)) { | ||
66 | + for (final onClose in _routesByCreate[disposed]!) { | ||
67 | + // assure the [DisposableInterface] instance holding a reference | ||
68 | + // to onClose() wasn't disposed. | ||
69 | + onClose(); | ||
70 | + } | ||
71 | + _routesByCreate[disposed]!.clear(); | ||
72 | + _routesByCreate.remove(disposed); | ||
73 | + } | ||
74 | + | ||
75 | + for (final element in keysToRemove) { | ||
76 | + GetInstance().reload(key: element, closeInstance: false); | ||
77 | + //_routesKey.remove(element); | ||
78 | + } | ||
79 | + | ||
80 | + keysToRemove.clear(); | ||
81 | + } | ||
82 | + | ||
83 | + /// Clears from memory registered Instances associated with [routeName] when | ||
84 | + /// using `Get.smartManagement` as [SmartManagement.full] or | ||
85 | + /// [SmartManagement.keepFactory] | ||
86 | + /// Meant for internal usage of `GetPageRoute` and `GetDialogRoute` | ||
87 | + static void _removeDependencyByRoute(Route routeName) { | ||
88 | + final keysToRemove = <String>[]; | ||
89 | + _routesKey.forEach((key, value) { | ||
90 | + if (value == routeName) { | ||
91 | + keysToRemove.add(key); | ||
92 | + } | ||
93 | + }); | ||
94 | + | ||
95 | + /// Removes `Get.create()` instances registered in `routeName`. | ||
96 | + if (_routesByCreate.containsKey(routeName)) { | ||
97 | + for (final onClose in _routesByCreate[routeName]!) { | ||
98 | + // assure the [DisposableInterface] instance holding a reference | ||
99 | + // to onClose() wasn't disposed. | ||
100 | + onClose(); | ||
101 | + } | ||
102 | + _routesByCreate[routeName]!.clear(); | ||
103 | + _routesByCreate.remove(routeName); | ||
104 | + } | ||
105 | + | ||
106 | + for (final element in keysToRemove) { | ||
107 | + GetInstance().delete(key: element); | ||
108 | + _routesKey.remove(element); | ||
109 | + } | ||
110 | + | ||
111 | + keysToRemove.clear(); | ||
112 | + } | ||
113 | +} |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | 2 | ||
3 | import '../../../get.dart'; | 3 | import '../../../get.dart'; |
4 | +import '../router_report.dart'; | ||
4 | import 'custom_transition.dart'; | 5 | import 'custom_transition.dart'; |
5 | import 'get_transition_mixin.dart'; | 6 | import 'get_transition_mixin.dart'; |
6 | import 'route_middleware.dart'; | 7 | import 'route_middleware.dart'; |
@@ -34,14 +35,15 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | @@ -34,14 +35,15 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | ||
34 | this.maintainState = true, | 35 | this.maintainState = true, |
35 | bool fullscreenDialog = false, | 36 | bool fullscreenDialog = false, |
36 | this.middlewares, | 37 | this.middlewares, |
37 | - }) : reference = "$routeName: ${settings?.hashCode ?? page.hashCode}", | ||
38 | - super(settings: settings, fullscreenDialog: fullscreenDialog); | 38 | + }) : super(settings: settings, fullscreenDialog: fullscreenDialog) { |
39 | + RouterReportManager.reportCurrentRoute(this); | ||
40 | + } | ||
39 | 41 | ||
40 | @override | 42 | @override |
41 | final Duration transitionDuration; | 43 | final Duration transitionDuration; |
42 | final GetPageBuilder? page; | 44 | final GetPageBuilder? page; |
43 | final String? routeName; | 45 | final String? routeName; |
44 | - final String reference; | 46 | + //final String reference; |
45 | final CustomTransition? customTransition; | 47 | final CustomTransition? customTransition; |
46 | final Bindings? binding; | 48 | final Bindings? binding; |
47 | final Map<String, String>? parameter; | 49 | final Map<String, String>? parameter; |
@@ -73,13 +75,7 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | @@ -73,13 +75,7 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | ||
73 | @override | 75 | @override |
74 | void dispose() { | 76 | void dispose() { |
75 | super.dispose(); | 77 | super.dispose(); |
76 | - if (Get.smartManagement != SmartManagement.onlyBuilder) { | ||
77 | - WidgetsBinding.instance!.addPostFrameCallback((_) { | ||
78 | - if (Get.reference != reference) { | ||
79 | - GetInstance().removeDependencyByRoute("$reference"); | ||
80 | - } | ||
81 | - }); | ||
82 | - } | 78 | + RouterReportManager.reportRouteDispose(this); |
83 | 79 | ||
84 | // if (Get.smartManagement != SmartManagement.onlyBuilder) { | 80 | // if (Get.smartManagement != SmartManagement.onlyBuilder) { |
85 | // GetInstance().removeDependencyByRoute("$reference"); | 81 | // GetInstance().removeDependencyByRoute("$reference"); |
@@ -91,7 +87,6 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | @@ -91,7 +87,6 @@ class GetPageRoute<T> extends PageRoute<T> with GetPageRouteTransitionMixin<T> { | ||
91 | 87 | ||
92 | @override | 88 | @override |
93 | Widget buildContent(BuildContext context) { | 89 | Widget buildContent(BuildContext context) { |
94 | - Get.reference = reference; | ||
95 | final middlewareRunner = MiddlewareRunner(middlewares); | 90 | final middlewareRunner = MiddlewareRunner(middlewares); |
96 | final bindingsToBind = middlewareRunner.runOnBindingsStart(bindings); | 91 | final bindingsToBind = middlewareRunner.runOnBindingsStart(bindings); |
97 | 92 |
@@ -4,6 +4,7 @@ import '../../../../get_core/get_core.dart'; | @@ -4,6 +4,7 @@ import '../../../../get_core/get_core.dart'; | ||
4 | import '../../../../instance_manager.dart'; | 4 | import '../../../../instance_manager.dart'; |
5 | import '../../../get_navigation.dart'; | 5 | import '../../../get_navigation.dart'; |
6 | import '../../dialog/dialog_route.dart'; | 6 | import '../../dialog/dialog_route.dart'; |
7 | +import '../../router_report.dart'; | ||
7 | import '../../snackbar/snack_route.dart'; | 8 | import '../../snackbar/snack_route.dart'; |
8 | import '../default_route.dart'; | 9 | import '../default_route.dart'; |
9 | 10 | ||
@@ -47,11 +48,11 @@ String? _extractRouteName(Route? route) { | @@ -47,11 +48,11 @@ String? _extractRouteName(Route? route) { | ||
47 | } | 48 | } |
48 | 49 | ||
49 | if (route is GetDialogRoute) { | 50 | if (route is GetDialogRoute) { |
50 | - return route.name; | 51 | + return 'DIALOG ${route.hashCode}'; |
51 | } | 52 | } |
52 | 53 | ||
53 | if (route is GetModalBottomSheetRoute) { | 54 | if (route is GetModalBottomSheetRoute) { |
54 | - return route.name; | 55 | + return 'BOTTOMSHEET ${route.hashCode}'; |
55 | } | 56 | } |
56 | 57 | ||
57 | return null; | 58 | return null; |
@@ -105,7 +106,7 @@ class GetObserver extends NavigatorObserver { | @@ -105,7 +106,7 @@ class GetObserver extends NavigatorObserver { | ||
105 | Get.log("GOING TO ROUTE ${newRoute.name}"); | 106 | Get.log("GOING TO ROUTE ${newRoute.name}"); |
106 | } | 107 | } |
107 | 108 | ||
108 | - Get.reference = newRoute.name; | 109 | + RouterReportManager.reportCurrentRoute(route); |
109 | _routeSend?.update((value) { | 110 | _routeSend?.update((value) { |
110 | // Only PageRoute is allowed to change current value | 111 | // Only PageRoute is allowed to change current value |
111 | if (route is PageRoute) { | 112 | if (route is PageRoute) { |
@@ -142,8 +143,10 @@ class GetObserver extends NavigatorObserver { | @@ -142,8 +143,10 @@ class GetObserver extends NavigatorObserver { | ||
142 | } else if (currentRoute.isGetPageRoute) { | 143 | } else if (currentRoute.isGetPageRoute) { |
143 | Get.log("CLOSE TO ROUTE ${currentRoute.name}"); | 144 | Get.log("CLOSE TO ROUTE ${currentRoute.name}"); |
144 | } | 145 | } |
146 | + if (previousRoute != null) { | ||
147 | + RouterReportManager.reportCurrentRoute(previousRoute); | ||
148 | + } | ||
145 | 149 | ||
146 | - Get.reference = newRoute.name; | ||
147 | // Here we use a 'inverse didPush set', meaning that we use | 150 | // Here we use a 'inverse didPush set', meaning that we use |
148 | // previous route instead of 'route' because this is | 151 | // previous route instead of 'route' because this is |
149 | // a 'inverse push' | 152 | // a 'inverse push' |
@@ -178,7 +181,10 @@ class GetObserver extends NavigatorObserver { | @@ -178,7 +181,10 @@ class GetObserver extends NavigatorObserver { | ||
178 | Get.log("REPLACE ROUTE $oldName"); | 181 | Get.log("REPLACE ROUTE $oldName"); |
179 | Get.log("NEW ROUTE $newName"); | 182 | Get.log("NEW ROUTE $newName"); |
180 | 183 | ||
181 | - Get.reference = newName; | 184 | + if (oldRoute != null) { |
185 | + RouterReportManager.reportCurrentRoute(oldRoute); | ||
186 | + } | ||
187 | + | ||
182 | _routeSend?.update((value) { | 188 | _routeSend?.update((value) { |
183 | // Only PageRoute is allowed to change current value | 189 | // Only PageRoute is allowed to change current value |
184 | if (newRoute is PageRoute) { | 190 | if (newRoute is PageRoute) { |
@@ -196,7 +202,7 @@ class GetObserver extends NavigatorObserver { | @@ -196,7 +202,7 @@ class GetObserver extends NavigatorObserver { | ||
196 | value.isDialog = currentRoute.isDialog ? false : value.isDialog; | 202 | value.isDialog = currentRoute.isDialog ? false : value.isDialog; |
197 | }); | 203 | }); |
198 | if (oldRoute is GetPageRoute) { | 204 | if (oldRoute is GetPageRoute) { |
199 | - GetInstance().reloadDependencyByRoute(oldRoute.reference); | 205 | + RouterReportManager.reportRouteWillDispose(oldRoute); |
200 | } | 206 | } |
201 | 207 | ||
202 | routing?.call(_routeSend); | 208 | routing?.call(_routeSend); |
@@ -222,7 +228,7 @@ class GetObserver extends NavigatorObserver { | @@ -222,7 +228,7 @@ class GetObserver extends NavigatorObserver { | ||
222 | }); | 228 | }); |
223 | 229 | ||
224 | if (route is GetPageRoute) { | 230 | if (route is GetPageRoute) { |
225 | - GetInstance().reloadDependencyByRoute(route.reference); | 231 | + RouterReportManager.reportRouteWillDispose(route); |
226 | } | 232 | } |
227 | routing?.call(_routeSend); | 233 | routing?.call(_routeSend); |
228 | } | 234 | } |
-
Please register or login to post a comment