Showing
1 changed file
with
118 additions
and
46 deletions
@@ -29,54 +29,76 @@ class GetImpl implements GetService { | @@ -29,54 +29,76 @@ class GetImpl implements GetService { | ||
29 | RouteSettings settings; | 29 | RouteSettings settings; |
30 | String defaultSeparator = "_"; | 30 | String defaultSeparator = "_"; |
31 | 31 | ||
32 | - ///Use to instead of Navigator.push, off instead of Navigator.pushReplacement, | ||
33 | - ///offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" | ||
34 | - ///after them. Example: toNamed, offNamed, and AllNamed. | ||
35 | - ///To return to the previous screen, use back(). | ||
36 | - ///No need to pass any context to Get, just put the name of the route inside | ||
37 | - ///the parentheses and the magic will occur. | ||
38 | - | ||
39 | - /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push | 32 | + /// Pushes a new [page] to the stack |
33 | + /// | ||
34 | + /// It has the advantage of not needing context, so you can call from your business logic | ||
35 | + /// | ||
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]. | ||
38 | + /// If you're using the [Bindings] api, it's here that you use it | ||
39 | + /// | ||
40 | + /// It replaces Navigator.push and it doesn't have the Navigator.push | ||
40 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 41 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
41 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 42 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
42 | - Future<T> to<T>(Widget page, | ||
43 | - {bool opaque, | ||
44 | - Transition transition, | ||
45 | - Duration duration, | ||
46 | - int id, | ||
47 | - bool fullscreenDialog = false, | ||
48 | - Object arguments, | ||
49 | - Bindings binding, | ||
50 | - preventDuplicates = true, | ||
51 | - bool popGesture}) { | 43 | + Future<T> to<T>( |
44 | + Widget page, { | ||
45 | + bool opaque, | ||
46 | + Transition transition, | ||
47 | + Duration duration, | ||
48 | + int id, | ||
49 | + bool fullscreenDialog = false, | ||
50 | + Object arguments, | ||
51 | + Bindings binding, | ||
52 | + preventDuplicates = true, | ||
53 | + bool popGesture, | ||
54 | + }) { | ||
52 | if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { | 55 | if (preventDuplicates && '/${page.runtimeType}' == currentRoute) { |
53 | return null; | 56 | return null; |
54 | } | 57 | } |
55 | 58 | ||
56 | - return global(id).currentState.push(GetPageRoute( | ||
57 | - opaque: opaque ?? true, | ||
58 | - page: () => page, | ||
59 | - settings: | ||
60 | - RouteSettings(name: '/${page.runtimeType}', arguments: arguments), | ||
61 | - popGesture: popGesture ?? defaultPopGesture, | ||
62 | - transition: transition ?? defaultTransition, | ||
63 | - fullscreenDialog: fullscreenDialog, | ||
64 | - binding: binding, | ||
65 | - transitionDuration: duration ?? defaultDurationTransition)); | ||
66 | - } | ||
67 | - | ||
68 | - /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | ||
69 | - /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | ||
70 | - /// of rebuilding every app after a route, use opaque = true as the parameter. | ||
71 | - Future<T> toNamed<T>(String page, | ||
72 | - {Object arguments, int id, preventDuplicates = true}) { | 59 | + return global(id).currentState.push( |
60 | + GetPageRoute( | ||
61 | + opaque: opaque ?? true, | ||
62 | + page: () => page, | ||
63 | + settings: RouteSettings( | ||
64 | + name: '/${page.runtimeType}', | ||
65 | + arguments: arguments, | ||
66 | + ), | ||
67 | + popGesture: popGesture ?? defaultPopGesture, | ||
68 | + transition: transition ?? defaultTransition, | ||
69 | + fullscreenDialog: fullscreenDialog, | ||
70 | + binding: binding, | ||
71 | + transitionDuration: duration ?? defaultDurationTransition, | ||
72 | + ), | ||
73 | + ); | ||
74 | + } | ||
75 | + | ||
76 | + /// Pushes a new named [page] to the stack | ||
77 | + /// | ||
78 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
79 | + /// | ||
80 | + /// You can send any type of value to the other route in the [arguments]. | ||
81 | + /// | ||
82 | + /// Note: Always put a slash on the route ('/page1'), since this package expects that | ||
83 | + Future<T> toNamed<T>( | ||
84 | + String page, { | ||
85 | + Object arguments, | ||
86 | + int id, | ||
87 | + preventDuplicates = true, | ||
88 | + }) { | ||
73 | if (preventDuplicates && page == currentRoute) { | 89 | if (preventDuplicates && page == currentRoute) { |
74 | return null; | 90 | return null; |
75 | } | 91 | } |
76 | return global(id).currentState.pushNamed(page, arguments: arguments); | 92 | return global(id).currentState.pushNamed(page, arguments: arguments); |
77 | } | 93 | } |
78 | 94 | ||
79 | - /// It replaces Navigator.pushReplacementNamed, but needs no context. | 95 | + /// Pop the current named [page] in the stack and push a new one in its place |
96 | + /// | ||
97 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
98 | + /// | ||
99 | + /// You can send any type of value to the other route in the [arguments]. | ||
100 | + /// | ||
101 | + /// Note: Always put a slash on the route ('/page1'), since this package expects that | ||
80 | Future<T> offNamed<T>(String page, | 102 | Future<T> offNamed<T>(String page, |
81 | {Object arguments, int id, preventDuplicates = true}) { | 103 | {Object arguments, int id, preventDuplicates = true}) { |
82 | if (preventDuplicates && page == currentRoute) { | 104 | if (preventDuplicates && page == currentRoute) { |
@@ -87,21 +109,30 @@ class GetImpl implements GetService { | @@ -87,21 +109,30 @@ class GetImpl implements GetService { | ||
87 | .pushReplacementNamed(page, arguments: arguments); | 109 | .pushReplacementNamed(page, arguments: arguments); |
88 | } | 110 | } |
89 | 111 | ||
90 | - /// It replaces Navigator.popUntil, but needs no context. | 112 | + /// Calls pop several times in the stack until [predicate] returns true |
113 | + /// | ||
114 | + /// TODO: complement this doc | ||
91 | void until(RoutePredicate predicate, {int id}) { | 115 | void until(RoutePredicate predicate, {int id}) { |
92 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 116 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
93 | // when widget don't mounted | 117 | // when widget don't mounted |
94 | return global(id).currentState.popUntil(predicate); | 118 | return global(id).currentState.popUntil(predicate); |
95 | } | 119 | } |
96 | 120 | ||
97 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | 121 | + /// Push the given [page], and then pop several [pages] in the stack until |
122 | + /// [predicate] returns true | ||
123 | + /// | ||
124 | + /// TODO: complement this doc | ||
98 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { | 125 | Future<T> offUntil<T>(Route<T> page, RoutePredicate predicate, {int id}) { |
99 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 126 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
100 | // when widget don't mounted | 127 | // when widget don't mounted |
101 | return global(id).currentState.pushAndRemoveUntil(page, predicate); | 128 | return global(id).currentState.pushAndRemoveUntil(page, predicate); |
102 | } | 129 | } |
103 | 130 | ||
104 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 131 | + /// Push the given named [page], and then pop several [pages] in the stack |
132 | + /// until [predicate] returns true | ||
133 | + /// | ||
134 | + /// You can send any type of value to the other route in the [arguments]. | ||
135 | + /// TODO: complement this doc | ||
105 | Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, | 136 | Future<T> offNamedUntil<T>(String page, RoutePredicate predicate, |
106 | {int id, Object arguments}) { | 137 | {int id, Object arguments}) { |
107 | return global(id) | 138 | return global(id) |
@@ -109,7 +140,11 @@ class GetImpl implements GetService { | @@ -109,7 +140,11 @@ class GetImpl implements GetService { | ||
109 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); | 140 | .pushNamedAndRemoveUntil(page, predicate, arguments: arguments); |
110 | } | 141 | } |
111 | 142 | ||
112 | - /// It replaces Navigator.popAndPushNamed, but needs no context. | 143 | + /// Pop the current named page and pushes a new [page] to the stack in its place |
144 | + /// | ||
145 | + /// 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 | ||
113 | Future<T> offAndToNamed<T>(String page, | 148 | Future<T> offAndToNamed<T>(String page, |
114 | {Object arguments, int id, dynamic result}) { | 149 | {Object arguments, int id, dynamic result}) { |
115 | return global(id) | 150 | return global(id) |
@@ -117,12 +152,18 @@ class GetImpl implements GetService { | @@ -117,12 +152,18 @@ class GetImpl implements GetService { | ||
117 | .popAndPushNamed(page, arguments: arguments, result: result); | 152 | .popAndPushNamed(page, arguments: arguments, result: result); |
118 | } | 153 | } |
119 | 154 | ||
120 | - /// It replaces Navigator.removeRoute, but needs no context. | 155 | + /// Remove a specific [route] from the stack |
121 | void removeRoute(Route<dynamic> route, {int id}) { | 156 | void removeRoute(Route<dynamic> route, {int id}) { |
122 | return global(id).currentState.removeRoute(route); | 157 | return global(id).currentState.removeRoute(route); |
123 | } | 158 | } |
124 | 159 | ||
125 | - /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 160 | + /// Push a named page and remove all other pages from stack |
161 | + /// | ||
162 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
163 | + /// | ||
164 | + /// You can send any type of value to the other route in the [arguments]. | ||
165 | + /// | ||
166 | + /// Note: Always put a slash on the route ('/page1'), since this package expects that | ||
126 | Future<T> offAllNamed<T>(String newRouteName, | 167 | Future<T> offAllNamed<T>(String newRouteName, |
127 | {RoutePredicate predicate, Object arguments, int id}) { | 168 | {RoutePredicate predicate, Object arguments, int id}) { |
128 | var route = (Route<dynamic> rota) => false; | 169 | var route = (Route<dynamic> rota) => false; |
@@ -132,13 +173,22 @@ class GetImpl implements GetService { | @@ -132,13 +173,22 @@ class GetImpl implements GetService { | ||
132 | arguments: arguments); | 173 | arguments: arguments); |
133 | } | 174 | } |
134 | 175 | ||
176 | + /// Returns true if a snackbar, dialog or bottomsheet is currently showing in the screen | ||
135 | bool get isOverlaysOpen => | 177 | bool get isOverlaysOpen => |
136 | (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | 178 | (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); |
137 | 179 | ||
180 | + /// returns true if there is no snackbar, dialog or bottomsheet open | ||
138 | bool get isOverlaysClosed => | 181 | bool get isOverlaysClosed => |
139 | (!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen); | 182 | (!isSnackbarOpen && !isDialogOpen && !isBottomSheetOpen); |
140 | 183 | ||
141 | - /// It replaces Navigator.pop, but needs no context. | 184 | + /// Pop the current page, snackbar, dialog or bottomsheet in the stack |
185 | + /// | ||
186 | + /// if your set [closeOverlays] to true, Get.back() will close the currently open | ||
187 | + /// snackbar/dialog/bottomsheet AND the current page | ||
188 | + /// | ||
189 | + /// TODO: ask jonatas about "canPop" | ||
190 | + /// | ||
191 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
142 | void back( | 192 | void back( |
143 | {dynamic result, | 193 | {dynamic result, |
144 | bool closeOverlays = false, | 194 | bool closeOverlays = false, |
@@ -158,7 +208,7 @@ class GetImpl implements GetService { | @@ -158,7 +208,7 @@ class GetImpl implements GetService { | ||
158 | } | 208 | } |
159 | } | 209 | } |
160 | 210 | ||
161 | - /// It will close as many screens as you define. Times must be> 0; | 211 | + /// Close as many routes as defined by [times] |
162 | void close(int times, [int id]) { | 212 | void close(int times, [int id]) { |
163 | if ((times == null) || (times < 1)) { | 213 | if ((times == null) || (times < 1)) { |
164 | times = 1; | 214 | times = 1; |
@@ -170,7 +220,17 @@ class GetImpl implements GetService { | @@ -170,7 +220,17 @@ class GetImpl implements GetService { | ||
170 | return back; | 220 | return back; |
171 | } | 221 | } |
172 | 222 | ||
173 | - /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement | 223 | + /// Pop the current [page] in the stack and push a new one in its place |
224 | + /// | ||
225 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
226 | + /// | ||
227 | + /// You can send any type of value to the other route in the [arguments]. | ||
228 | + /// | ||
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]. | ||
231 | + /// If you're using the [Bindings] api, it's here that you use it | ||
232 | + /// | ||
233 | + /// It replaces Navigator.pushReplacement and it doesn't have the Navigator.pushReplacement | ||
174 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 234 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
175 | /// of rebuilding every app after a route, use opaque = true as the parameter. | 235 | /// of rebuilding every app after a route, use opaque = true as the parameter. |
176 | Future<T> off<T>(Widget page, | 236 | Future<T> off<T>(Widget page, |
@@ -198,7 +258,19 @@ class GetImpl implements GetService { | @@ -198,7 +258,19 @@ class GetImpl implements GetService { | ||
198 | transitionDuration: duration ?? defaultDurationTransition)); | 258 | transitionDuration: duration ?? defaultDurationTransition)); |
199 | } | 259 | } |
200 | 260 | ||
201 | - /// It replaces Navigator.pushAndRemoveUntil, but needs no context | 261 | + /// Pop all pages of the stack and push a new one |
262 | + /// | ||
263 | + /// It has the advantage of not needing context, so you can call from your business logic. | ||
264 | + /// | ||
265 | + /// You can send any type of value to the other route in the [arguments]. | ||
266 | + /// | ||
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]. | ||
269 | + /// If you're using the [Bindings] api, it's here that you use it | ||
270 | + /// | ||
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. | ||
202 | Future<T> offAll<T>(Widget page, | 274 | Future<T> offAll<T>(Widget page, |
203 | {RoutePredicate predicate, | 275 | {RoutePredicate predicate, |
204 | bool opaque = false, | 276 | bool opaque = false, |
-
Please register or login to post a comment