Line data Source code
1 : import 'package:flutter/widgets.dart';
2 : import 'package:get/src/root/smart_management.dart';
3 : import '../../get_instance.dart';
4 : import '../../get_main.dart';
5 :
6 : class Routing {
7 : String current;
8 : String previous;
9 : Object args;
10 : String removed;
11 : Route<dynamic> route;
12 : bool isBack;
13 : bool isSnackbar;
14 : bool isBottomSheet;
15 : bool isDialog;
16 8 : Routing({
17 : this.current,
18 : this.previous,
19 : this.args,
20 : this.removed,
21 : this.route,
22 : this.isBack,
23 : this.isSnackbar,
24 : this.isBottomSheet,
25 : this.isDialog,
26 : });
27 : }
28 :
29 : class GetObserver extends NavigatorObserver {
30 : final Function(Routing) routing;
31 :
32 3 : GetObserver([this.routing]);
33 :
34 : Route<dynamic> route;
35 : bool isBack;
36 : bool isSnackbar;
37 : bool isBottomSheet;
38 : bool isDialog;
39 : String current;
40 : String previous;
41 : Object args;
42 : // String previousArgs;
43 : String removed;
44 :
45 3 : @override
46 : void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
47 9 : if ('${route?.settings?.name}' == 'snackbar') {
48 : if (GetConfig.isLogEnable)
49 4 : print("[OPEN SNACKBAR] ${route?.settings?.name}");
50 9 : } else if ('${route?.settings?.name}' == 'bottomsheet') {
51 : if (GetConfig.isLogEnable)
52 4 : print("[OPEN BOTTOMSHEET] ${route?.settings?.name}");
53 9 : } else if ('${route?.settings?.name}' == 'dialog') {
54 : if (GetConfig.isLogEnable)
55 4 : print("[OPEN DIALOG] ${route?.settings?.name}");
56 : } else {
57 : if (GetConfig.isLogEnable)
58 12 : print("[GOING TO ROUTE] ${route?.settings?.name}");
59 : }
60 :
61 12 : isSnackbar = '${route?.settings?.name}' == 'snackbar';
62 12 : isDialog = '${route?.settings?.name}' == 'dialog';
63 12 : isBottomSheet = '${route?.settings?.name}' == 'bottomsheet';
64 12 : current = '${route?.settings?.name}';
65 12 : previous = '${previousRoute?.settings?.name}';
66 9 : args = route?.settings?.arguments;
67 : // previousArgs = previousRoute?.settings?.arguments;
68 :
69 3 : final routeSend = Routing(
70 : removed: null,
71 : isBack: false,
72 : route: route,
73 9 : current: '${route?.settings?.name}',
74 9 : previous: '${previousRoute?.settings?.name}',
75 6 : args: route?.settings?.arguments,
76 : // previousArgs: previousRoute?.settings?.arguments,
77 3 : isSnackbar: isSnackbar,
78 3 : isDialog: isDialog,
79 3 : isBottomSheet: isBottomSheet,
80 : );
81 3 : if (routing != null) {
82 0 : routing(routeSend);
83 : }
84 3 : GetConfig.currentRoute = current;
85 6 : Get.setRouting(routeSend);
86 : }
87 :
88 3 : @override
89 : void didPop(Route route, Route previousRoute) {
90 3 : super.didPop(route, previousRoute);
91 :
92 9 : if ('${route?.settings?.name}' == 'snackbar') {
93 : if (GetConfig.isLogEnable)
94 4 : print("[CLOSE SNACKBAR] ${route?.settings?.name}");
95 9 : } else if ('${route?.settings?.name}' == 'bottomsheet') {
96 : if (GetConfig.isLogEnable)
97 4 : print("[CLOSE BOTTOMSHEET] ${route?.settings?.name}");
98 6 : } else if ('${route?.settings?.name}' == 'dialog') {
99 : if (GetConfig.isLogEnable)
100 4 : print("[CLOSE DIALOG] ${route?.settings?.name}");
101 : } else {
102 4 : if (GetConfig.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}");
103 : }
104 :
105 6 : if (GetConfig.smartManagement != SmartManagement.onlyBuilder) {
106 15 : GetInstance().removeDependencyByRoute("${route?.settings?.name}");
107 : }
108 :
109 3 : isSnackbar = false;
110 3 : isDialog = false;
111 3 : isBottomSheet = false;
112 12 : current = '${previousRoute?.settings?.name}';
113 12 : previous = '${route?.settings?.name}';
114 9 : args = previousRoute?.settings?.arguments;
115 : // previousArgs = route?.settings?.arguments;
116 :
117 3 : final routeSend = Routing(
118 : removed: null,
119 : isBack: true,
120 : route: previousRoute,
121 9 : current: '${previousRoute?.settings?.name}',
122 9 : previous: '${route?.settings?.name}',
123 6 : args: previousRoute?.settings?.arguments,
124 : // previousArgs: route?.settings?.arguments,
125 : isSnackbar: false, //'${route?.settings?.name}' == 'snackbar',
126 : isDialog: false, //'${route?.settings?.name}' == 'dialog',
127 : isBottomSheet: false, //'${route?.settings?.name}' == 'bottomsheet',
128 : );
129 :
130 3 : if (routing != null) {
131 0 : routing(routeSend);
132 : }
133 3 : GetConfig.currentRoute = current;
134 6 : Get.setRouting(routeSend);
135 : }
136 :
137 1 : @override
138 : void didReplace({Route newRoute, Route oldRoute}) {
139 1 : super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
140 : if (GetConfig.isLogEnable)
141 4 : print("[REPLACE ROUTE] ${oldRoute?.settings?.name}");
142 4 : if (GetConfig.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}");
143 :
144 2 : if (GetConfig.smartManagement == SmartManagement.full) {
145 5 : GetInstance().removeDependencyByRoute("${oldRoute?.settings?.name}");
146 : }
147 :
148 1 : isSnackbar = false;
149 1 : isDialog = false;
150 1 : isBottomSheet = false;
151 :
152 1 : final routeSend = Routing(
153 : removed: null, // add '${oldRoute?.settings?.name}' or remain null ???
154 : isBack: false,
155 : route: newRoute,
156 3 : current: '${newRoute?.settings?.name}',
157 3 : previous: '${oldRoute?.settings?.name}',
158 2 : args: newRoute?.settings?.arguments,
159 : // previousArgs: newRoute?.settings?.arguments,
160 : isSnackbar: false,
161 : isBottomSheet: false,
162 : isDialog: false,
163 : );
164 :
165 1 : if (routing != null) {
166 0 : routing(routeSend);
167 : }
168 1 : GetConfig.currentRoute = current;
169 2 : Get.setRouting(routeSend);
170 : }
171 :
172 1 : @override
173 : void didRemove(Route route, Route previousRoute) {
174 1 : super.didRemove(route, previousRoute);
175 : if (GetConfig.isLogEnable)
176 4 : print("[REMOVING ROUTE] ${route?.settings?.name}");
177 :
178 2 : if (GetConfig.smartManagement == SmartManagement.full) {
179 5 : GetInstance().removeDependencyByRoute("${route?.settings?.name}");
180 : }
181 :
182 1 : final routeSend = Routing(
183 : isBack: false,
184 : route: previousRoute,
185 : // current: '${previousRoute?.settings?.name}',
186 1 : current: current,
187 1 : args: args,
188 3 : removed: '${route?.settings?.name}',
189 : // args: previousRoute?.settings?.arguments,
190 1 : isSnackbar: isSnackbar,
191 1 : isBottomSheet: isBottomSheet,
192 1 : isDialog: isDialog,
193 : // previousArgs: route?.settings?.arguments,
194 : );
195 :
196 1 : if (routing != null) {
197 0 : routing(routeSend);
198 : }
199 1 : GetConfig.currentRoute = current;
200 2 : Get.setRouting(routeSend);
201 : }
202 : }
|