Showing
1 changed file
with
146 additions
and
50 deletions
@@ -31,15 +31,26 @@ class GetImpl implements GetService { | @@ -31,15 +31,26 @@ class GetImpl implements GetService { | ||
31 | 31 | ||
32 | /// Pushes a new [page] to the stack | 32 | /// Pushes a new [page] to the stack |
33 | /// | 33 | /// |
34 | - /// It has the advantage of not needing context, so you can call from your business logic | 34 | + /// It has the advantage of not needing context, |
35 | + /// so you can call from your business logic | ||
36 | + /// | ||
37 | + /// You can set a custom [transition], and a transition [duration]. | ||
35 | /// | 38 | /// |
36 | - /// You can set a custom [transition], a transition [duration]. | ||
37 | /// You can send any type of value to the other route in the [arguments]. | 39 | /// You can send any type of value to the other route in the [arguments]. |
38 | - /// If you're using the [Bindings] api, it's here that you use it | ||
39 | /// | 40 | /// |
40 | - /// It replaces Navigator.push and it doesn't have the Navigator.push | ||
41 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
42 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | 41 | + /// Just like native routing in Flutter, you can push a route |
42 | + /// as a [fullscreenDialog], | ||
43 | + /// | ||
44 | + /// [id] is for when you are using nested navigation, | ||
45 | + /// as explained in documentation | ||
46 | + /// | ||
47 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
48 | + /// you can set [popGesture] to true | ||
49 | + /// | ||
50 | + /// If you're using the [Bindings] api, you must define it here | ||
51 | + /// | ||
52 | + /// By default, GetX will prevent you from push a route that you already in, | ||
53 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
43 | Future<T> to<T>( | 54 | Future<T> to<T>( |
44 | Widget page, { | 55 | Widget page, { |
45 | bool opaque, | 56 | bool opaque, |
@@ -75,11 +86,18 @@ class GetImpl implements GetService { | @@ -75,11 +86,18 @@ class GetImpl implements GetService { | ||
75 | 86 | ||
76 | /// Pushes a new named [page] to the stack | 87 | /// Pushes a new named [page] to the stack |
77 | /// | 88 | /// |
78 | - /// It has the advantage of not needing context, so you can call from your business logic. | 89 | + /// It has the advantage of not needing context, so you can call |
90 | + /// from your business logic. | ||
79 | /// | 91 | /// |
80 | /// You can send any type of value to the other route in the [arguments]. | 92 | /// You can send any type of value to the other route in the [arguments]. |
81 | /// | 93 | /// |
82 | - /// Note: Always put a slash on the route ('/page1'), since this package expects that | 94 | + /// [id] is for when you are using nested navigation, |
95 | + /// as explained in documentation | ||
96 | + /// | ||
97 | + /// By default, GetX will prevent you from push a route that you already in, | ||
98 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
99 | + /// | ||
100 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
83 | Future<T> toNamed<T>( | 101 | Future<T> toNamed<T>( |
84 | String page, { | 102 | String page, { |
85 | Object arguments, | 103 | Object arguments, |
@@ -94,13 +112,24 @@ class GetImpl implements GetService { | @@ -94,13 +112,24 @@ class GetImpl implements GetService { | ||
94 | 112 | ||
95 | /// Pop the current named [page] in the stack and push a new one in its place | 113 | /// Pop the current named [page] in the stack and push a new one in its place |
96 | /// | 114 | /// |
97 | - /// It has the advantage of not needing context, so you can call from your business logic. | 115 | + /// It has the advantage of not needing context, so you can call |
116 | + /// from your business logic. | ||
98 | /// | 117 | /// |
99 | /// You can send any type of value to the other route in the [arguments]. | 118 | /// You can send any type of value to the other route in the [arguments]. |
100 | /// | 119 | /// |
101 | - /// Note: Always put a slash on the route ('/page1'), since this package expects that | ||
102 | - Future<T> offNamed<T>(String page, | ||
103 | - {Object arguments, int id, preventDuplicates = true}) { | 120 | + /// [id] is for when you are using nested navigation, |
121 | + /// as explained in documentation | ||
122 | + /// | ||
123 | + /// By default, GetX will prevent you from push a route that you already in, | ||
124 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
125 | + /// | ||
126 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
127 | + Future<T> offNamed<T>( | ||
128 | + String page, { | ||
129 | + Object arguments, | ||
130 | + int id, | ||
131 | + preventDuplicates = true, | ||
132 | + }) { | ||
104 | if (preventDuplicates && page == currentRoute) { | 133 | if (preventDuplicates && page == currentRoute) { |
105 | return null; | 134 | return null; |
106 | } | 135 | } |
@@ -111,7 +140,14 @@ class GetImpl implements GetService { | @@ -111,7 +140,14 @@ class GetImpl implements GetService { | ||
111 | 140 | ||
112 | /// Calls pop several times in the stack until [predicate] returns true | 141 | /// Calls pop several times in the stack until [predicate] returns true |
113 | /// | 142 | /// |
114 | - /// TODO: complement this doc | 143 | + /// [id] is for when you are using nested navigation, |
144 | + /// as explained in documentation | ||
145 | + /// | ||
146 | + /// [predicate] can be used like this: | ||
147 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
148 | + /// | ||
149 | + /// or also like this: | ||
150 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
115 | void until(RoutePredicate predicate, {int id}) { | 151 | void until(RoutePredicate predicate, {int id}) { |
116 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 152 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
117 | // when widget don't mounted | 153 | // when widget don't mounted |
@@ -121,20 +157,40 @@ class GetImpl implements GetService { | @@ -121,20 +157,40 @@ class GetImpl implements GetService { | ||
121 | /// Push the given [page], and then pop several [pages] in the stack until | 157 | /// Push the given [page], and then pop several [pages] in the stack until |
122 | /// [predicate] returns true | 158 | /// [predicate] returns true |
123 | /// | 159 | /// |
124 | - /// TODO: complement this doc | 160 | + /// [id] is for when you are using nested navigation, |
161 | + /// as explained in documentation | ||
162 | + /// | ||
163 | + /// [predicate] can be used like this: | ||
164 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
165 | + /// | ||
166 | + /// or also like this: | ||
167 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
125 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { | 168 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { |
126 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 169 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
127 | // when widget don't mounted | 170 | // when widget don't mounted |
128 | return global(id).currentState.pushAndRemoveUntil(page, predicate); | 171 | return global(id).currentState.pushAndRemoveUntil(page, predicate); |
129 | } | 172 | } |
130 | 173 | ||
131 | - /// Push the given named [page], and then pop several [pages] in the stack | 174 | + /// Push the given named [page], and then pop several pages in the stack |
132 | /// until [predicate] returns true | 175 | /// until [predicate] returns true |
133 | /// | 176 | /// |
134 | /// You can send any type of value to the other route in the [arguments]. | 177 | /// You can send any type of value to the other route in the [arguments]. |
135 | - /// TODO: complement this doc | ||
136 | - Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, | ||
137 | - {int id, Object arguments}) { | 178 | + /// |
179 | + /// [id] is for when you are using nested navigation, | ||
180 | + /// as explained in documentation | ||
181 | + /// | ||
182 | + /// [predicate] can be used like this: | ||
183 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
184 | + /// or also like | ||
185 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
186 | + /// | ||
187 | + /// Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors | ||
188 | + Future<T> offNamedUntil<T>( | ||
189 | + String page, | ||
190 | + RoutePredicate predicate, { | ||
191 | + int id, | ||
192 | + Object arguments, | ||
193 | + }) { | ||
138 | return global(id) | 194 | return global(id) |
139 | .currentState | 195 | .currentState |
140 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); | 196 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); |
@@ -143,8 +199,11 @@ class GetImpl implements GetService { | @@ -143,8 +199,11 @@ class GetImpl implements GetService { | ||
143 | /// Pop the current named page and pushes a new [page] to the stack in its place | 199 | /// Pop the current named page and pushes a new [page] to the stack in its place |
144 | /// | 200 | /// |
145 | /// You can send any type of value to the other route in the [arguments]. | 201 | /// You can send any type of value to the other route in the [arguments]. |
146 | - /// TODO: complement this doc | ||
147 | - /// TODO: ask jonatas what is that result argument | 202 | + /// It is very similar to `offNamed()` but use a different approach |
203 | + /// | ||
204 | + /// The `offNamed()` pop a page, and goes to the next. The `offAndToNamed()` goes | ||
205 | + /// to the next page, and removes the previous one. The route transition | ||
206 | + /// animation is different. | ||
148 | Future<T> offAndToNamed<T>(String page, | 207 | Future<T> offAndToNamed<T>(String page, |
149 | {Object arguments, int id, dynamic result}) { | 208 | {Object arguments, int id, dynamic result}) { |
150 | return global(id) | 209 | return global(id) |
@@ -153,17 +212,24 @@ class GetImpl implements GetService { | @@ -153,17 +212,24 @@ class GetImpl implements GetService { | ||
153 | } | 212 | } |
154 | 213 | ||
155 | /// Remove a specific [route] from the stack | 214 | /// Remove a specific [route] from the stack |
215 | + /// | ||
216 | + /// [id] is for when you are using nested navigation, | ||
217 | + /// as explained in documentation | ||
156 | void removeRoute(Route<dynamic> route, {int id}) { | 218 | void removeRoute(Route<dynamic> route, {int id}) { |
157 | return global(id).currentState.removeRoute(route); | 219 | return global(id).currentState.removeRoute(route); |
158 | } | 220 | } |
159 | 221 | ||
160 | - /// Push a named page and remove all other pages from stack | 222 | + /// Push a named [page] and remove all other pages from stack |
161 | /// | 223 | /// |
162 | - /// It has the advantage of not needing context, so you can call from your business logic. | 224 | + /// It has the advantage of not needing context, so you can |
225 | + /// call from your business logic. | ||
163 | /// | 226 | /// |
164 | /// You can send any type of value to the other route in the [arguments]. | 227 | /// You can send any type of value to the other route in the [arguments]. |
165 | /// | 228 | /// |
166 | - /// Note: Always put a slash on the route ('/page1'), since this package expects that | 229 | + /// [id] is for when you are using nested navigation, |
230 | + /// as explained in documentation | ||
231 | + /// | ||
232 | + /// Note: Always put a slash on the route ('/page1'), to avoid unexpected errors | ||
167 | Future<T> offAllNamed<T>(String newRouteName, | 233 | Future<T> offAllNamed<T>(String newRouteName, |
168 | {RoutePredicate predicate, Object arguments, int id}) { | 234 | {RoutePredicate predicate, Object arguments, int id}) { |
169 | var route = (Route<dynamic> rota) => false; | 235 | var route = (Route<dynamic> rota) => false; |
@@ -186,14 +252,17 @@ class GetImpl implements GetService { | @@ -186,14 +252,17 @@ class GetImpl implements GetService { | ||
186 | /// if your set [closeOverlays] to true, Get.back() will close the currently open | 252 | /// if your set [closeOverlays] to true, Get.back() will close the currently open |
187 | /// snackbar/dialog/bottomsheet AND the current page | 253 | /// snackbar/dialog/bottomsheet AND the current page |
188 | /// | 254 | /// |
189 | - /// TODO: ask jonatas about "canPop" | 255 | + /// [id] is for when you are using nested navigation, |
256 | + /// as explained in documentation | ||
190 | /// | 257 | /// |
191 | - /// It has the advantage of not needing context, so you can call from your business logic. | ||
192 | - void back( | ||
193 | - {dynamic result, | 258 | + /// It has the advantage of not needing context, so you can call |
259 | + /// from your business logic. | ||
260 | + void back({ | ||
261 | + dynamic result, | ||
194 | bool closeOverlays = false, | 262 | bool closeOverlays = false, |
195 | bool canPop = true, | 263 | bool canPop = true, |
196 | - int id}) { | 264 | + int id, |
265 | + }) { | ||
197 | if (closeOverlays && isOverlaysOpen) { | 266 | if (closeOverlays && isOverlaysOpen) { |
198 | navigator.popUntil((route) { | 267 | navigator.popUntil((route) { |
199 | return (isOverlaysClosed); | 268 | return (isOverlaysClosed); |
@@ -220,21 +289,31 @@ class GetImpl implements GetService { | @@ -220,21 +289,31 @@ class GetImpl implements GetService { | ||
220 | return back; | 289 | return back; |
221 | } | 290 | } |
222 | 291 | ||
223 | - /// Pop the current [page] in the stack and push a new one in its place | 292 | + /// Pop the current page and pushes a new [page] to the stack |
224 | /// | 293 | /// |
225 | - /// It has the advantage of not needing context, so you can call from your business logic. | 294 | + /// It has the advantage of not needing context, |
295 | + /// so you can call from your business logic | ||
226 | /// | 296 | /// |
227 | - /// You can send any type of value to the other route in the [arguments]. | 297 | + /// You can set a custom [transition], and a transition [duration]. |
228 | /// | 298 | /// |
229 | - /// You can set a custom [transition], a transition [duration]. | ||
230 | /// You can send any type of value to the other route in the [arguments]. | 299 | /// You can send any type of value to the other route in the [arguments]. |
231 | - /// If you're using the [Bindings] api, it's here that you use it | ||
232 | /// | 300 | /// |
233 | - /// It replaces Navigator.pushReplacement and it doesn't have the Navigator.pushReplacement | ||
234 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
235 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
236 | - Future<T> off<T>(Widget page, | ||
237 | - {bool opaque = false, | 301 | + /// Just like native routing in Flutter, you can push a route |
302 | + /// as a [fullscreenDialog], | ||
303 | + /// | ||
304 | + /// [id] is for when you are using nested navigation, | ||
305 | + /// as explained in documentation | ||
306 | + /// | ||
307 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
308 | + /// you can set [popGesture] to true | ||
309 | + /// | ||
310 | + /// If you're using the [Bindings] api, you must define it here | ||
311 | + /// | ||
312 | + /// By default, GetX will prevent you from push a route that you already in, | ||
313 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
314 | + Future<T> off<T>( | ||
315 | + Widget page, { | ||
316 | + bool opaque = false, | ||
238 | Transition transition, | 317 | Transition transition, |
239 | bool popGesture, | 318 | bool popGesture, |
240 | int id, | 319 | int id, |
@@ -242,7 +321,8 @@ class GetImpl implements GetService { | @@ -242,7 +321,8 @@ class GetImpl implements GetService { | ||
242 | Bindings binding, | 321 | Bindings binding, |
243 | bool fullscreenDialog = false, | 322 | bool fullscreenDialog = false, |
244 | preventDuplicates = true, | 323 | preventDuplicates = true, |
245 | - Duration duration}) { | 324 | + Duration duration, |
325 | + }) { | ||
246 | if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | 326 | if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { |
247 | return null; | 327 | return null; |
248 | } | 328 | } |
@@ -258,21 +338,36 @@ class GetImpl implements GetService { | @@ -258,21 +338,36 @@ class GetImpl implements GetService { | ||
258 | transitionDuration: duration ?? defaultDurationTransition)); | 338 | transitionDuration: duration ?? defaultDurationTransition)); |
259 | } | 339 | } |
260 | 340 | ||
261 | - /// Pop all pages of the stack and push a new one | 341 | + /// Pop all pages in the stack and pushes a new [page] to it |
262 | /// | 342 | /// |
263 | - /// It has the advantage of not needing context, so you can call from your business logic. | 343 | + /// It has the advantage of not needing context, |
344 | + /// so you can call from your business logic | ||
264 | /// | 345 | /// |
265 | - /// You can send any type of value to the other route in the [arguments]. | 346 | + /// You can set a custom [transition], and a transition [duration]. |
266 | /// | 347 | /// |
267 | - /// You can set a custom [transition] and a transition [duration]. | ||
268 | /// You can send any type of value to the other route in the [arguments]. | 348 | /// You can send any type of value to the other route in the [arguments]. |
269 | - /// If you're using the [Bindings] api, it's here that you use it | ||
270 | /// | 349 | /// |
271 | - /// It replaces Navigator.pushReplacement and it doesn't have the Navigator.pushReplacement | ||
272 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
273 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
274 | - Future<T> offAll<T>(Widget page, | ||
275 | - {RoutePredicate predicate, | 350 | + /// Just like native routing in Flutter, you can push a route |
351 | + /// as a [fullscreenDialog], | ||
352 | + /// | ||
353 | + /// [predicate] can be used like this: | ||
354 | + /// `Get.until(Get.currentRoute == '/home')`so when you get to home page, | ||
355 | + /// or also like | ||
356 | + /// `Get.until(!Get.isDialogOpen())`, to make sure the dialog is closed | ||
357 | + /// | ||
358 | + /// [id] is for when you are using nested navigation, | ||
359 | + /// as explained in documentation | ||
360 | + /// | ||
361 | + /// If you want the same behavior of ios that pops a route when the user drag, | ||
362 | + /// you can set [popGesture] to true | ||
363 | + /// | ||
364 | + /// If you're using the [Bindings] api, you must define it here | ||
365 | + /// | ||
366 | + /// By default, GetX will prevent you from push a route that you already in, | ||
367 | + /// if you want to push anyway, set [preventDuplicates] to false | ||
368 | + Future<T> offAll<T>( | ||
369 | + Widget page, { | ||
370 | + RoutePredicate predicate, | ||
276 | bool opaque = false, | 371 | bool opaque = false, |
277 | bool popGesture, | 372 | bool popGesture, |
278 | int id, | 373 | int id, |
@@ -280,7 +375,8 @@ class GetImpl implements GetService { | @@ -280,7 +375,8 @@ class GetImpl implements GetService { | ||
280 | Bindings binding, | 375 | Bindings binding, |
281 | bool fullscreenDialog = false, | 376 | bool fullscreenDialog = false, |
282 | Duration duration, | 377 | Duration duration, |
283 | - Transition transition}) { | 378 | + Transition transition, |
379 | + }) { | ||
284 | var route = (Route<dynamic> rota) => false; | 380 | var route = (Route<dynamic> rota) => false; |
285 | 381 | ||
286 | return global(id).currentState.pushAndRemoveUntil( | 382 | return global(id).currentState.pushAndRemoveUntil( |
-
Please register or login to post a comment