Showing
18 changed files
with
883 additions
and
641 deletions
@@ -208,3 +208,23 @@ | @@ -208,3 +208,23 @@ | ||
208 | ## [1.20.0-dev] | 208 | ## [1.20.0-dev] |
209 | - Added Get Instance Manager | 209 | - Added Get Instance Manager |
210 | Get.put / Get.find / Get.delete | 210 | Get.put / Get.find / Get.delete |
211 | + | ||
212 | +## [1.20.1-dev] | ||
213 | +- Improve: Get.finds | ||
214 | + | ||
215 | +## [2.0.0-dev] | ||
216 | +- Added easy state manager | ||
217 | +- Cleaner code | ||
218 | +- Improve Get | ||
219 | +- Change dialog API | ||
220 | +- Added GetMaterialApp | ||
221 | +- Added new experimental APIs | ||
222 | +- Improve Observer | ||
223 | +- Added default duration on Transitions | ||
224 | +- Added new routeNamed sistem | ||
225 | +- Added Global stateManager config | ||
226 | +- Improve Get instance manager | ||
227 | +- Added routingCallback | ||
228 | +- Added closeOverlays to Get.back | ||
229 | +- Added dynamic urls | ||
230 | +- Many APIs added |
1 | # Get | 1 | # Get |
2 | 2 | ||
3 | -A consistent navigation library that lets you navigate between screens, open dialogs/bottomSheets, and display snackbars from anywhere in your code without context. | ||
4 | -## Getting Started | ||
5 | - | ||
6 | -*Languages: [English](README.md), [Brazilian Portuguese](README.pt-br.md).* | ||
7 | - | ||
8 | -Flutter's conventional navigation has a lot of unnecessary boilerplate, requires context to navigate between screens, open dialogs, and use snackbars on framework is really painful. | ||
9 | -In addition, when a route is pushed, the entire MaterialApp can be rebuilt causing freezes, this does not happen with Get. | ||
10 | -This library that will change the way you work with the Framework and save your life from cliche code, increasing your productivity, and eliminating the rebuild bugs of your application. | 3 | +Get is an extra-light and powerful microframework for Flutter that will give you superpowers and increase your productivity. Navigate without context, open dialogs, snackbars or bottomsheets from anywhere in your code in an easy and practical way. |
4 | +Get is secure, stable, up-to-date, and offers a huge range of APIs that are not present in the standard framework. | ||
11 | 5 | ||
12 | ```dart | 6 | ```dart |
13 | // Default Flutter navigator | 7 | // Default Flutter navigator |
@@ -23,23 +17,28 @@ Navigator.of(context).push( | @@ -23,23 +17,28 @@ Navigator.of(context).push( | ||
23 | // Get sintax | 17 | // Get sintax |
24 | Get.to(Home()); | 18 | Get.to(Home()); |
25 | ``` | 19 | ``` |
20 | +*Languages: [English](README.md), [Brazilian Portuguese](README.pt-br.md).* | ||
21 | +## Getting Started | ||
22 | + | ||
23 | +Flutter's conventional navigation has a lot of unnecessary boilerplate, requires context to navigate between screens, open dialogs, and use snackbars on framework is really boring. | ||
24 | +In addition, when a route is pushed, the entire MaterialApp can be rebuilt causing freezes, this does not happen with Get. | ||
25 | +This library that will change the way you work with the Framework and save your life from cliche code, increasing your productivity, and eliminating the rebuild bugs of your application. | ||
26 | + | ||
26 | ## How to use? | 27 | ## How to use? |
27 | 28 | ||
29 | +- Flutter Master/Dev/Beta: version 2.0.0-dev | ||
30 | +- Flutter Stable branch: version 1.17.3 | ||
31 | + | ||
28 | Add this to your package's pubspec.yaml file: | 32 | Add this to your package's pubspec.yaml file: |
29 | 33 | ||
30 | ``` | 34 | ``` |
31 | dependencies: | 35 | dependencies: |
32 | - get: ^1.17.3 // ^1.20.0-dev on beta/dev/master | 36 | + get: ^1.17.3 // ^2.0.0-dev on beta/dev/master |
33 | ``` | 37 | ``` |
34 | - | ||
35 | -And import it: | 38 | +Exchange your MaterialApp for GetMaterialApp and enjoy! |
36 | ```dart | 39 | ```dart |
37 | import 'package:get/get.dart'; | 40 | import 'package:get/get.dart'; |
38 | -``` | ||
39 | -Add GetKey to your MaterialApp and enjoy: | ||
40 | -```dart | ||
41 | -MaterialApp( | ||
42 | - navigatorKey: Get.key, | 41 | +GetMaterialApp( // Before: MaterialApp( |
43 | home: MyHome(), | 42 | home: MyHome(), |
44 | ) | 43 | ) |
45 | ``` | 44 | ``` |
@@ -218,8 +217,7 @@ Get.bottomSheet is like showModalBottomSheet, but don't need of context. | @@ -218,8 +217,7 @@ Get.bottomSheet is like showModalBottomSheet, but don't need of context. | ||
218 | 217 | ||
219 | ```dart | 218 | ```dart |
220 | Get.bottomSheet( | 219 | Get.bottomSheet( |
221 | - builder: (_){ | ||
222 | - return Container( | 220 | + Container( |
223 | child: Wrap( | 221 | child: Wrap( |
224 | children: <Widget>[ | 222 | children: <Widget>[ |
225 | ListTile( | 223 | ListTile( |
@@ -238,19 +236,108 @@ Get.bottomSheet( | @@ -238,19 +236,108 @@ Get.bottomSheet( | ||
238 | } | 236 | } |
239 | ); | 237 | ); |
240 | ``` | 238 | ``` |
241 | -### Global configurations | ||
242 | -You can create Global settings for Get. Just add Get.config to your code before pushing any route | ||
243 | 239 | ||
240 | +## Simple State Manager | ||
241 | +There are currently several state managers for Flutter. However, most of them involve using an inheritedWidget to access your data through context and use ChangeNotifier to update widgets (like the Provider), or are too complex for beginners (like BLoC), others are easy and reactive (like MobX) however they need to use a code generator. | ||
242 | +So I created in just 95 lines of code this easy and light state manager, which does not use ChangeNotifier (ChangeNotifier is bad for performance, and which will supply the need especially for those who are new to Flutter. Get is omniscient, this means that it has access to any Flutter API, whether inside or outside the widget tree. The Get state manager updates only the necessary Widget, uses the widgets' own memory status to update, making it more efficient than ChangeNotifier, and does not use InheritedWidget, giving you full control of the state of your application. This does not mean that it is the best state manager, but it is an ideal solution for certain types of users. | ||
243 | + | ||
244 | +Get's state manager is perfect for the MVC standard, and you can use it like this: | ||
244 | ```dart | 245 | ```dart |
245 | -Get.config( | ||
246 | - enableLog = true, | ||
247 | - defaultPopGesture = true, | ||
248 | - defaultTransition = Transitions.cupertino} | 246 | +// Create controller class and extends GetController |
247 | +class Controller extends GetController { | ||
248 | + int counter = 0; | ||
249 | + void increment() { | ||
250 | + counter++; | ||
251 | + update(this); // use update(this) to update counter variable um UI when increment be called | ||
252 | + } | ||
253 | +} | ||
254 | +// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called | ||
255 | +GetBuilder( | ||
256 | + controller: controller, | ||
257 | + builder: (_) => Text( | ||
258 | + '${_.counter}', | ||
259 | + )), | ||
249 | ``` | 260 | ``` |
261 | +**Done!** | ||
262 | +- You have already learned how to manage states with Get. | ||
250 | 263 | ||
251 | -## Simple Instance Manager | ||
252 | -Are you already using Get and want to make your project as lean as possible? Now Get has a simple manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code. | 264 | +### Global State manager |
253 | 265 | ||
266 | +If you navigate many routes and need data that was in your previously used controller, you just need to send Get to find the controller in memory for you! | ||
267 | + | ||
268 | +```dart | ||
269 | +class OtherClasse extends StatelessWidget { | ||
270 | + @override | ||
271 | + Widget build(BuildContext context) { | ||
272 | + Controller controller = Get.find(); | ||
273 | + return Scaffold( | ||
274 | + body: Center( | ||
275 | + child: GetBuilder( | ||
276 | + controller: controller, | ||
277 | + builder: (_) => Text( | ||
278 | + '${_.counter}', | ||
279 | + style: Theme.of(context).textTheme.headline4, | ||
280 | + ), | ||
281 | + ), | ||
282 | + ), | ||
283 | + ); | ||
284 | + } | ||
285 | + | ||
286 | +``` | ||
287 | +If you don't want to instantiate your controller whenever you need to use it, you can create a get directly on your controller and access it statically. | ||
288 | + | ||
289 | +```dart | ||
290 | +class Controller extends GetController { | ||
291 | + static Controller get to => Get.find(); // add this line | ||
292 | + int counter = 0; | ||
293 | + void increment() { | ||
294 | + counter++; | ||
295 | + update(this); | ||
296 | + } | ||
297 | +} | ||
298 | +``` | ||
299 | +And then you can access your controller directly, that way: | ||
300 | +```dart | ||
301 | +FloatingActionButton( | ||
302 | + onPressed: Controller.to.increment, // This is incredibly simple! | ||
303 | + child: Icon(Icons.add), | ||
304 | + ), | ||
305 | +``` | ||
306 | +When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically. | ||
307 | + | ||
308 | +##### Different forms of use: | ||
309 | + | ||
310 | +You can use controlador instance directly on GetBuilder: | ||
311 | +```dart | ||
312 | +GetBuilder( | ||
313 | + controller: Controller(), //here | ||
314 | + builder: (_) => Text( | ||
315 | + '${_.counter}', | ||
316 | + )), | ||
317 | +``` | ||
318 | +You can type your GetBuilder to access the IDE's autocomplete | ||
319 | +```dart | ||
320 | +GetBuilder<Controller>( //here | ||
321 | + controller: Controller(), | ||
322 | + builder: (value) => Text( | ||
323 | + '${value.counter}', //here | ||
324 | + )), | ||
325 | +``` | ||
326 | + | ||
327 | +You can to use controller instance: | ||
328 | +```dart | ||
329 | +Controller controller = Controller(); | ||
330 | +[...] | ||
331 | +GetBuilder( | ||
332 | + controller: controller, //here | ||
333 | + builder: (_) => Text( | ||
334 | + '${controller.counter}', // here | ||
335 | + )), | ||
336 | +``` | ||
337 | + | ||
338 | + | ||
339 | +## Simple Instance Manager | ||
340 | +Are you already using Get and want to make your project as lean as possible? Now Get has a simple instance manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code. | ||
254 | 341 | ||
255 | ```dart | 342 | ```dart |
256 | Controller controller = Get.put(Controller()); // Rather Controller controller = Controller(); | 343 | Controller controller = Get.put(Controller()); // Rather Controller controller = Controller(); |
@@ -281,7 +368,7 @@ Get.delete(Controller()); | @@ -281,7 +368,7 @@ Get.delete(Controller()); | ||
281 | 368 | ||
282 | 369 | ||
283 | ## Navigate with named routes: | 370 | ## Navigate with named routes: |
284 | -- If you prefer to browse selected routes, or Get also supports this. | 371 | +- If you prefer to navigate by namedRoutes, Get also supports this. |
285 | 372 | ||
286 | To navigate to nextScreen | 373 | To navigate to nextScreen |
287 | ```dart | 374 | ```dart |
@@ -296,6 +383,21 @@ To navigate and remove all previous screens from the tree. | @@ -296,6 +383,21 @@ To navigate and remove all previous screens from the tree. | ||
296 | Get.offAllNamed("/NextScreen"); | 383 | Get.offAllNamed("/NextScreen"); |
297 | ``` | 384 | ``` |
298 | 385 | ||
386 | +To define routes, use GetMaterialApp: | ||
387 | + | ||
388 | +```dart | ||
389 | +void main() { | ||
390 | + runApp(GetMaterialApp( | ||
391 | + initialRoute: '/', | ||
392 | + namedRoutes: { | ||
393 | + '/': GetRoute(page: MyHomePage()), | ||
394 | + '/second': GetRoute(page: Second()), | ||
395 | + '/third': GetRoute(page: Third(),transition: Transition.cupertino); | ||
396 | + }, | ||
397 | + )); | ||
398 | +} | ||
399 | +``` | ||
400 | + | ||
299 | ### Send data to named Routes: | 401 | ### Send data to named Routes: |
300 | 402 | ||
301 | Just send what you want for arguments. Get accepts anything here, whether it is a String, a Map, a List, or even a class instance. | 403 | Just send what you want for arguments. Get accepts anything here, whether it is a String, a Map, a List, or even a class instance. |
@@ -309,61 +411,63 @@ print(Get.arguments); | @@ -309,61 +411,63 @@ print(Get.arguments); | ||
309 | //print out: Get is the best | 411 | //print out: Get is the best |
310 | ``` | 412 | ``` |
311 | 413 | ||
312 | -## Configure the Named Routes and And offering full flutter_web support to friendly urls: | 414 | +#### Dynamic urls links |
415 | +Get is the first and only package to offer advanced dynamic urls just like on the Web. Web developers have probably already wanted this feature on Flutter, and most likely have seen a package promise this feature and deliver a totally different syntax than a URL would have on web, but Get also solves that. | ||
416 | + | ||
417 | +```dart | ||
418 | +Get.offAllNamed("/NextScreen?device=phone&id=354&name=Enzo"); | ||
419 | +``` | ||
420 | +on your controller/bloc/stateful/stateless class: | ||
421 | + | ||
422 | +```dart | ||
423 | +print(Get.parameters['id']); | ||
424 | +// out: 354 | ||
425 | +print(Get.parameters['name']); | ||
426 | +// out: Enzo | ||
427 | +``` | ||
313 | 428 | ||
314 | -### If you have not yet added "navigatorKey: Get.key," to your MaterialApp, do it now. Take the opportunity to add an "initialRoute" and your "onGenerateRoute". | 429 | +You can also receive NamedParameters with Get easily: |
315 | 430 | ||
316 | ```dart | 431 | ```dart |
317 | void main() { | 432 | void main() { |
318 | - runApp(MaterialApp( | ||
319 | - onGenerateRoute: Router.generateRoute, | ||
320 | - initialRoute: "/", | ||
321 | - navigatorKey: Get.key, | ||
322 | - title: 'Navigation', | 433 | + runApp(GetMaterialApp( |
434 | + initialRoute: '/', | ||
435 | + namedRoutes: { | ||
436 | + '/': GetRoute(page: MyHomePage()), | ||
437 | + '/second/:user': GetRoute(page: Second()), // receive ID | ||
438 | + '/third': GetRoute(page: Third(),transition: Transition.cupertino); | ||
439 | + }, | ||
323 | )); | 440 | )); |
324 | } | 441 | } |
325 | ``` | 442 | ``` |
443 | +Send data on route name | ||
444 | +```dart | ||
445 | +Get.toNamed("/second/34954"); | ||
446 | +``` | ||
326 | 447 | ||
327 | -Copy this Router class below and put it in your app, rename routes and classes for your own, add more classes to it if necessary. | 448 | +On second screen take the data by parameter |
328 | 449 | ||
329 | ```dart | 450 | ```dart |
330 | -class Router { | ||
331 | - static Route<dynamic> generateRoute(RouteSettings settings) { | ||
332 | - switch (settings.name) { | ||
333 | - case '/': | ||
334 | - return GetRoute( | ||
335 | - page: First(), | ||
336 | - settings: settings, | ||
337 | - ); | ||
338 | - case '/second': | ||
339 | - return GetRoute( | ||
340 | - settings: settings, page: Second(), transition: Transition.fade); | ||
341 | - case '/third': | ||
342 | - return GetRoute( | ||
343 | - settings: settings, | ||
344 | - page: Third(), | ||
345 | - popGesture: true, | ||
346 | - transition: Transition.cupertino); | ||
347 | - default: | ||
348 | - return GetRoute( | ||
349 | - settings: settings, | ||
350 | - transition: Transition.fade, | ||
351 | - page: Scaffold( | ||
352 | - body: | ||
353 | - Center(child: Text('No route defined for ${settings.name}')), | ||
354 | - )); | ||
355 | - } | ||
356 | - } | ||
357 | -} | 451 | +print(Get.parameters['user']); |
452 | +// out: 34954 | ||
358 | ``` | 453 | ``` |
359 | 454 | ||
360 | And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (you can call your routes directly from your BLoC or Controller class), and when your app is compiled to the web, your routes will appear in the url <3 | 455 | And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (you can call your routes directly from your BLoC or Controller class), and when your app is compiled to the web, your routes will appear in the url <3 |
361 | 456 | ||
362 | 457 | ||
363 | #### Middleware | 458 | #### Middleware |
364 | -If you want listen Get events to trigger actions, you can add a GetObserver to your materialApp. This is extremely useful for triggering events whenever a specific Screen is displayed on the screen. Currently on Flutter you would have to put the event on initState and wait for a possible response in a navigator.pop (context); to get that. But with Get, this is extremely simple! | 459 | +If you want listen Get events to trigger actions, you can to use routingCallback to it |
460 | +```dart | ||
461 | +GetMaterialApp( | ||
462 | + routingCallback: (route){ | ||
463 | + if(routing.current == '/second'){ | ||
464 | + openAds(); | ||
465 | + } | ||
466 | + } | ||
467 | + ``` | ||
468 | +If you are not using GetMaterialApp, you can use the manual API to attach Middleware observer. | ||
469 | + | ||
365 | 470 | ||
366 | -##### add GetObserver(); | ||
367 | ```dart | 471 | ```dart |
368 | void main() { | 472 | void main() { |
369 | runApp(MaterialApp( | 473 | runApp(MaterialApp( |
@@ -466,18 +570,34 @@ class Third extends StatelessWidget { | @@ -466,18 +570,34 @@ class Third extends StatelessWidget { | ||
466 | } | 570 | } |
467 | ``` | 571 | ``` |
468 | 572 | ||
573 | +### Optional Global Settings | ||
574 | +You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp | ||
575 | + | ||
576 | +```dart | ||
577 | + | ||
578 | +GetMaterialApp( | ||
579 | + enableLog: true, | ||
580 | + defaultTransition: Transitions.fade, | ||
581 | + defaultOpaqueRoute: Get.isOpaqueRouteDefault, | ||
582 | + defaultPopGesture: Get.isPopGestureEnable, | ||
583 | + defaultDurationTransition: Get.defaultDurationTransition, | ||
584 | + defaultGlobalState: Get.defaultGlobalState, | ||
585 | + ); | ||
469 | 586 | ||
470 | -### Advanced APIs | ||
471 | -Each day Get gets further away from the standard Framework, and provides a wider range of features that are unthinkable to be executed using the standard Flutter. | ||
472 | -With Get 1.17.0 a range of new APIs was launched, which allow access from arguments of a named route to whether there is a snackbar or dialog open at that moment, or which screen is being displayed. | ||
473 | -This is a big step towards completely detaching the Flutter navigation from InheritedWidgets. Using context to access an InheritedWidget to access a simple navigation feature is one of the only boring things to do in this incredible framework, and now Get has solved this problem, it has become omniscient, and you will have access to basically any tool Flutter which is only available within the widget tree using it. | 587 | +Get.config( |
588 | + enableLog = true, | ||
589 | + defaultPopGesture = true, | ||
590 | + defaultTransition = Transitions.cupertino} | ||
591 | +``` | ||
474 | 592 | ||
475 | -All APIs available here are in beta stage, so if you find any errors here, open an issue or offer a PR. | 593 | + |
594 | +### Other Advanced APIs and Manual configurations | ||
595 | +GetMaterialApp configures everything for you, but if you are using any package like Modular, you may want to configure Get Manually using advanced APIs. | ||
476 | 596 | ||
477 | ```dart | 597 | ```dart |
478 | MaterialApp( | 598 | MaterialApp( |
479 | navigatorKey: Get.key, | 599 | navigatorKey: Get.key, |
480 | - navigatorObservers: [GetObserver()], // ADD THIS !!!! | 600 | + navigatorObservers: [GetObserver()], |
481 | ); | 601 | ); |
482 | ``` | 602 | ``` |
483 | 603 | ||
@@ -507,8 +627,24 @@ Get.isDialogOpen // check if dialog is open | @@ -507,8 +627,24 @@ Get.isDialogOpen // check if dialog is open | ||
507 | 627 | ||
508 | Get.isBottomSheetOpen // check if bottomsheet is open | 628 | Get.isBottomSheetOpen // check if bottomsheet is open |
509 | 629 | ||
630 | +Get.removeRoute() // remove one route. | ||
631 | + | ||
632 | +Get.until() // back repeatedly until the predicate returns true. | ||
633 | + | ||
634 | +Get.offUntil() // go to next route and remove all the previous routes until the predicate returns true. | ||
635 | + | ||
636 | +Get.offNamedUntil() // go to next named route and remove all the previous routes until the predicate returns true. | ||
637 | + | ||
638 | +GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid") | ||
639 | + | ||
640 | +Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height | ||
641 | + | ||
642 | +Get.context // Gives the context of the screen in the foreground anywhere in your code. | ||
643 | + | ||
644 | +Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in the foreground anywhere in your code. | ||
510 | 645 | ||
511 | ``` | 646 | ``` |
647 | + | ||
512 | ### Nested Navigators | 648 | ### Nested Navigators |
513 | 649 | ||
514 | Get made Flutter's nested navigation even easier. | 650 | Get made Flutter's nested navigation even easier. |
@@ -554,25 +690,4 @@ See how simple it is: | @@ -554,25 +690,4 @@ See how simple it is: | ||
554 | ``` | 690 | ``` |
555 | 691 | ||
556 | 692 | ||
557 | -### Others methods (docs will be added soon): | ||
558 | - | ||
559 | -```dart | ||
560 | -Get.removeRoute() // remove one route. | ||
561 | - | ||
562 | -Get.until() // back repeatedly until the predicate returns true. | ||
563 | - | ||
564 | -Get.offUntil() // go to next route and remove all the previous routes until the predicate returns true. | ||
565 | - | ||
566 | -Get.offNamedUntil() // go to next named route and remove all the previous routes until the predicate returns true. | ||
567 | - | ||
568 | -GetPlatform.isAndroid/isIOS/isWeb... //(This method is completely compatible with FlutterWeb, unlike the framework. "Platform.isAndroid") | ||
569 | - | ||
570 | -Get.height / Get.width // Equivalent to the method: MediaQuery.of(context).size.height | ||
571 | - | ||
572 | -Get.context // Gives the context of the screen in the foreground anywhere in your code. | ||
573 | - | ||
574 | -Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in the foreground anywhere in your code. | ||
575 | - | ||
576 | -``` | ||
577 | - | ||
578 | This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them. | 693 | This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them. |
@@ -69,7 +69,7 @@ | @@ -69,7 +69,7 @@ | ||
69 | }, | 69 | }, |
70 | { | 70 | { |
71 | "name": "get", | 71 | "name": "get", |
72 | - "rootUri": "file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/get-1.11.6", | 72 | + "rootUri": "file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/get-1.15.2", |
73 | "packageUri": "lib/", | 73 | "packageUri": "lib/", |
74 | "languageVersion": "2.1" | 74 | "languageVersion": "2.1" |
75 | }, | 75 | }, |
@@ -176,7 +176,7 @@ | @@ -176,7 +176,7 @@ | ||
176 | "languageVersion": "2.1" | 176 | "languageVersion": "2.1" |
177 | } | 177 | } |
178 | ], | 178 | ], |
179 | - "generated": "2020-04-02T04:26:33.309754Z", | 179 | + "generated": "2020-04-27T06:02:27.159254Z", |
180 | "generator": "pub", | 180 | "generator": "pub", |
181 | - "generatorVersion": "2.8.0-dev.18.0.flutter-e8c4aed700" | 181 | + "generatorVersion": "2.8.0-dev.20.10" |
182 | } | 182 | } |
1 | -# Generated by pub on 2020-04-02 01:26:33.285366. | 1 | +# Generated by pub on 2020-04-27 03:02:27.132181. |
2 | archive:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.13/lib/ | 2 | archive:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.13/lib/ |
3 | args:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/ | 3 | args:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/ |
4 | async:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.4.1/lib/ | 4 | async:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.4.1/lib/ |
@@ -10,7 +10,7 @@ crypto:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.4/lib/ | @@ -10,7 +10,7 @@ crypto:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.4/lib/ | ||
10 | cupertino_icons:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-0.1.3/lib/ | 10 | cupertino_icons:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-0.1.3/lib/ |
11 | flutter:file:///opt/flutter/packages/flutter/lib/ | 11 | flutter:file:///opt/flutter/packages/flutter/lib/ |
12 | flutter_test:file:///opt/flutter/packages/flutter_test/lib/ | 12 | flutter_test:file:///opt/flutter/packages/flutter_test/lib/ |
13 | -get:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/get-1.11.6/lib/ | 13 | +get:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/get-1.15.2/lib/ |
14 | image:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.1.12/lib/ | 14 | image:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/image-2.1.12/lib/ |
15 | matcher:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.6/lib/ | 15 | matcher:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.6/lib/ |
16 | meta:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/ | 16 | meta:file:///opt/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.1.8/lib/ |
@@ -80,7 +80,7 @@ packages: | @@ -80,7 +80,7 @@ packages: | ||
80 | name: get | 80 | name: get |
81 | url: "https://pub.dartlang.org" | 81 | url: "https://pub.dartlang.org" |
82 | source: hosted | 82 | source: hosted |
83 | - version: "1.11.6" | 83 | + version: "1.15.2" |
84 | image: | 84 | image: |
85 | dependency: transitive | 85 | dependency: transitive |
86 | description: | 86 | description: |
get.iml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<module type="JAVA_MODULE" version="4"> | ||
3 | + <component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
4 | + <exclude-output /> | ||
5 | + <content url="file://$MODULE_DIR$"> | ||
6 | + <excludeFolder url="file://$MODULE_DIR$/.dart_tool" /> | ||
7 | + <excludeFolder url="file://$MODULE_DIR$/.pub" /> | ||
8 | + <excludeFolder url="file://$MODULE_DIR$/build" /> | ||
9 | + <excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" /> | ||
10 | + <excludeFolder url="file://$MODULE_DIR$/example/.pub" /> | ||
11 | + <excludeFolder url="file://$MODULE_DIR$/example/build" /> | ||
12 | + </content> | ||
13 | + <orderEntry type="sourceFolder" forTests="false" /> | ||
14 | + <orderEntry type="library" name="Dart SDK" level="project" /> | ||
15 | + <orderEntry type="library" name="Dart Packages" level="project" /> | ||
16 | + </component> | ||
17 | +</module> |
@@ -5,6 +5,8 @@ export 'src/get_main.dart'; | @@ -5,6 +5,8 @@ export 'src/get_main.dart'; | ||
5 | export 'src/snackbar/snack.dart'; | 5 | export 'src/snackbar/snack.dart'; |
6 | export 'src/bottomsheet/bottomsheet.dart'; | 6 | export 'src/bottomsheet/bottomsheet.dart'; |
7 | export 'src/snackbar/snack_route.dart'; | 7 | export 'src/snackbar/snack_route.dart'; |
8 | +export 'src/state/get_state.dart'; | ||
9 | +export 'src/root/root_widget.dart'; | ||
8 | export 'src/routes/observers/route_observer.dart'; | 10 | export 'src/routes/observers/route_observer.dart'; |
9 | export 'src/routes/transitions_type.dart'; | 11 | export 'src/routes/transitions_type.dart'; |
10 | export 'src/platform/platform.dart'; | 12 | export 'src/platform/platform.dart'; |
lib/src/dialog/dialog.dart
deleted
100644 → 0
1 | -import 'package:flutter/material.dart'; | ||
2 | -import 'package:get/get.dart'; | ||
3 | - | ||
4 | -class DefaultDialogGet extends StatelessWidget { | ||
5 | - final color; | ||
6 | - final double opacity; | ||
7 | - final String title; | ||
8 | - final Widget content; | ||
9 | - final Widget cancel; | ||
10 | - final Widget confirm; | ||
11 | - | ||
12 | - const DefaultDialogGet( | ||
13 | - {Key key, | ||
14 | - this.color, | ||
15 | - this.opacity = 0.5, | ||
16 | - this.title, | ||
17 | - this.content, | ||
18 | - this.cancel, | ||
19 | - this.confirm}) | ||
20 | - : super(key: key); | ||
21 | - | ||
22 | - @override | ||
23 | - Widget build(BuildContext context) { | ||
24 | - return AlertDialog( | ||
25 | - title: Text(title, textAlign: TextAlign.center), | ||
26 | - content: content, | ||
27 | - actions: <Widget>[cancel, confirm], | ||
28 | - ); | ||
29 | - } | ||
30 | -} | ||
31 | - | ||
32 | -Future<T> getShowGeneralDialog<T>({ | ||
33 | - @required RoutePageBuilder pageBuilder, | ||
34 | - bool barrierDismissible, | ||
35 | - String barrierLabel, | ||
36 | - Color barrierColor, | ||
37 | - Duration transitionDuration, | ||
38 | - RouteTransitionsBuilder transitionBuilder, | ||
39 | - bool useRootNavigator = true, | ||
40 | -}) { | ||
41 | - assert(pageBuilder != null); | ||
42 | - assert(useRootNavigator != null); | ||
43 | - assert(!barrierDismissible || barrierLabel != null); | ||
44 | - return Get.key.currentState.push<T>(_DialogRoute<T>( | ||
45 | - pageBuilder: pageBuilder, | ||
46 | - settings: RouteSettings(name: "dialog"), | ||
47 | - barrierDismissible: barrierDismissible, | ||
48 | - barrierLabel: barrierLabel, | ||
49 | - barrierColor: barrierColor, | ||
50 | - transitionDuration: transitionDuration, | ||
51 | - transitionBuilder: transitionBuilder, | ||
52 | - )); | ||
53 | -} | ||
54 | - | ||
55 | -class _DialogRoute<T> extends PopupRoute<T> { | ||
56 | - _DialogRoute({ | ||
57 | - @required RoutePageBuilder pageBuilder, | ||
58 | - bool barrierDismissible = true, | ||
59 | - String barrierLabel, | ||
60 | - Color barrierColor = const Color(0x80000000), | ||
61 | - Duration transitionDuration = const Duration(milliseconds: 200), | ||
62 | - RouteTransitionsBuilder transitionBuilder, | ||
63 | - RouteSettings settings, | ||
64 | - }) : assert(barrierDismissible != null), | ||
65 | - _pageBuilder = pageBuilder, | ||
66 | - _barrierDismissible = barrierDismissible, | ||
67 | - _barrierLabel = barrierLabel, | ||
68 | - _barrierColor = barrierColor, | ||
69 | - _transitionDuration = transitionDuration, | ||
70 | - _transitionBuilder = transitionBuilder, | ||
71 | - super(settings: settings); | ||
72 | - | ||
73 | - final RoutePageBuilder _pageBuilder; | ||
74 | - | ||
75 | - @override | ||
76 | - bool get barrierDismissible => _barrierDismissible; | ||
77 | - final bool _barrierDismissible; | ||
78 | - | ||
79 | - @override | ||
80 | - String get barrierLabel => _barrierLabel; | ||
81 | - final String _barrierLabel; | ||
82 | - | ||
83 | - @override | ||
84 | - Color get barrierColor => _barrierColor; | ||
85 | - final Color _barrierColor; | ||
86 | - | ||
87 | - @override | ||
88 | - Duration get transitionDuration => _transitionDuration; | ||
89 | - final Duration _transitionDuration; | ||
90 | - | ||
91 | - final RouteTransitionsBuilder _transitionBuilder; | ||
92 | - | ||
93 | - @override | ||
94 | - Widget buildPage(BuildContext context, Animation<double> animation, | ||
95 | - Animation<double> secondaryAnimation) { | ||
96 | - return Semantics( | ||
97 | - child: _pageBuilder(context, animation, secondaryAnimation), | ||
98 | - scopesRoute: true, | ||
99 | - explicitChildNodes: true, | ||
100 | - ); | ||
101 | - } | ||
102 | - | ||
103 | - @override | ||
104 | - Widget buildTransitions(BuildContext context, Animation<double> animation, | ||
105 | - Animation<double> secondaryAnimation, Widget child) { | ||
106 | - if (_transitionBuilder == null) { | ||
107 | - return FadeTransition( | ||
108 | - opacity: CurvedAnimation( | ||
109 | - parent: animation, | ||
110 | - curve: Curves.linear, | ||
111 | - ), | ||
112 | - child: child); | ||
113 | - } // Some default transition | ||
114 | - return _transitionBuilder(context, animation, secondaryAnimation, child); | ||
115 | - } | ||
116 | -} |
1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
2 | import 'package:flutter/scheduler.dart'; | 2 | import 'package:flutter/scheduler.dart'; |
3 | -import 'package:get/src/dialog/dialog.dart'; | ||
4 | -import 'package:get/get.dart'; | ||
5 | -import '../get.dart'; | 3 | +import 'bottomsheet/bottomsheet.dart'; |
6 | import 'platform/platform.dart'; | 4 | import 'platform/platform.dart'; |
7 | import 'routes/default_route.dart'; | 5 | import 'routes/default_route.dart'; |
6 | +import 'routes/observers/route_observer.dart'; | ||
7 | +import 'routes/transitions_type.dart'; | ||
8 | +import 'snackbar/snack.dart'; | ||
8 | 9 | ||
9 | class Get { | 10 | class Get { |
10 | static Get _get; | 11 | static Get _get; |
@@ -46,6 +47,9 @@ class Get { | @@ -46,6 +47,9 @@ class Get { | ||
46 | static bool _defaultOpaqueRoute = true; | 47 | static bool _defaultOpaqueRoute = true; |
47 | static Transition _defaultTransition = | 48 | static Transition _defaultTransition = |
48 | (GetPlatform.isIOS ? Transition.cupertino : Transition.fade); | 49 | (GetPlatform.isIOS ? Transition.cupertino : Transition.fade); |
50 | + static Duration _defaultDurationTransition = Duration(milliseconds: 400); | ||
51 | + static bool _defaultGlobalState = true; | ||
52 | + static RouteSettings _settings; | ||
49 | 53 | ||
50 | /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push | 54 | /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push |
51 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior | 55 | /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior |
@@ -56,21 +60,12 @@ class Get { | @@ -56,21 +60,12 @@ class Get { | ||
56 | Duration duration, | 60 | Duration duration, |
57 | int id, | 61 | int id, |
58 | bool popGesture}) { | 62 | bool popGesture}) { |
59 | - if (id == null) { | ||
60 | - return key.currentState.push(GetRoute( | ||
61 | - opaque: opaque ?? true, | ||
62 | - page: page, | ||
63 | - popGesture: popGesture ?? _defaultPopGesture, | ||
64 | - transition: transition ?? _defaultTransition, | ||
65 | - transitionDuration: duration ?? const Duration(milliseconds: 400))); | ||
66 | - } else { | ||
67 | return global(id).currentState.push(GetRoute( | 63 | return global(id).currentState.push(GetRoute( |
68 | opaque: opaque ?? true, | 64 | opaque: opaque ?? true, |
69 | page: page, | 65 | page: page, |
70 | popGesture: popGesture ?? _defaultPopGesture, | 66 | popGesture: popGesture ?? _defaultPopGesture, |
71 | transition: transition ?? _defaultTransition, | 67 | transition: transition ?? _defaultTransition, |
72 | - transitionDuration: duration ?? const Duration(milliseconds: 400))); | ||
73 | - } | 68 | + transitionDuration: duration ?? _defaultDurationTransition)); |
74 | } | 69 | } |
75 | 70 | ||
76 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed | 71 | /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed |
@@ -79,91 +74,66 @@ class Get { | @@ -79,91 +74,66 @@ class Get { | ||
79 | static Future<T> toNamed<T>(String page, {arguments, int id}) { | 74 | static Future<T> toNamed<T>(String page, {arguments, int id}) { |
80 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 75 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
81 | // when widget don't mounted | 76 | // when widget don't mounted |
82 | - if (id == null) { | ||
83 | - return key.currentState.pushNamed(page, arguments: arguments); | ||
84 | - } else { | ||
85 | return global(id).currentState.pushNamed(page, arguments: arguments); | 77 | return global(id).currentState.pushNamed(page, arguments: arguments); |
86 | } | 78 | } |
87 | - } | ||
88 | 79 | ||
89 | /// It replaces Navigator.pushReplacementNamed, but needs no context. | 80 | /// It replaces Navigator.pushReplacementNamed, but needs no context. |
90 | static Future<T> offNamed<T>(String page, {arguments, int id}) { | 81 | static Future<T> offNamed<T>(String page, {arguments, int id}) { |
91 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 82 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
92 | // when widget don't mounted | 83 | // when widget don't mounted |
93 | - if (id == null) { | ||
94 | - return key.currentState.pushReplacementNamed(page, arguments: arguments); | ||
95 | - } else { | ||
96 | return global(id) | 84 | return global(id) |
97 | .currentState | 85 | .currentState |
98 | .pushReplacementNamed(page, arguments: arguments); | 86 | .pushReplacementNamed(page, arguments: arguments); |
99 | } | 87 | } |
100 | - } | ||
101 | 88 | ||
102 | /// It replaces Navigator.popUntil, but needs no context. | 89 | /// It replaces Navigator.popUntil, but needs no context. |
103 | - static void until(String page, predicate, {int id}) { | 90 | + static void until(predicate, {int id}) { |
104 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 91 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
105 | // when widget don't mounted | 92 | // when widget don't mounted |
106 | - if (id == null) { | ||
107 | - return key.currentState.popUntil(predicate); | ||
108 | - } else { | ||
109 | return global(id).currentState.popUntil(predicate); | 93 | return global(id).currentState.popUntil(predicate); |
110 | } | 94 | } |
111 | - } | ||
112 | 95 | ||
113 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. | 96 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context. |
114 | static Future<T> offUntil<T>(page, predicate, {int id}) { | 97 | static Future<T> offUntil<T>(page, predicate, {int id}) { |
115 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate | 98 | // if (key.currentState.mounted) // add this if appear problems on future with route navigate |
116 | // when widget don't mounted | 99 | // when widget don't mounted |
117 | - if (id == null) { | ||
118 | - return key.currentState.pushAndRemoveUntil(page, predicate); | ||
119 | - } else { | ||
120 | return global(id).currentState.pushAndRemoveUntil(page, predicate); | 100 | return global(id).currentState.pushAndRemoveUntil(page, predicate); |
121 | } | 101 | } |
122 | - } | ||
123 | 102 | ||
124 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 103 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
125 | static Future<T> offNamedUntil<T>(page, predicate, {int id}) { | 104 | static Future<T> offNamedUntil<T>(page, predicate, {int id}) { |
126 | - // if (key.currentState.mounted) // add this if appear problems on future with route navigate | ||
127 | - // when widget don't mounted | ||
128 | - if (id == null) { | ||
129 | - return key.currentState.pushNamedAndRemoveUntil(page, predicate); | ||
130 | - } else { | ||
131 | return global(id).currentState.pushNamedAndRemoveUntil(page, predicate); | 105 | return global(id).currentState.pushNamedAndRemoveUntil(page, predicate); |
132 | } | 106 | } |
133 | - } | ||
134 | 107 | ||
135 | /// It replaces Navigator.removeRoute, but needs no context. | 108 | /// It replaces Navigator.removeRoute, but needs no context. |
136 | static void removeRoute(route, {int id}) { | 109 | static void removeRoute(route, {int id}) { |
137 | - if (id == null) { | ||
138 | - return key.currentState.removeRoute(route); | ||
139 | - } else { | ||
140 | return global(id).currentState.removeRoute(route); | 110 | return global(id).currentState.removeRoute(route); |
141 | } | 111 | } |
142 | - } | ||
143 | 112 | ||
144 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. | 113 | /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. |
145 | static Future<T> offAllNamed<T>(String newRouteName, | 114 | static Future<T> offAllNamed<T>(String newRouteName, |
146 | {RoutePredicate predicate, arguments, int id}) { | 115 | {RoutePredicate predicate, arguments, int id}) { |
147 | var route = (Route<dynamic> rota) => false; | 116 | var route = (Route<dynamic> rota) => false; |
148 | 117 | ||
149 | - if (id == null) { | ||
150 | - return key.currentState.pushNamedAndRemoveUntil( | ||
151 | - newRouteName, predicate ?? route, | ||
152 | - arguments: arguments); | ||
153 | - } else { | ||
154 | return global(id).currentState.pushNamedAndRemoveUntil( | 118 | return global(id).currentState.pushNamedAndRemoveUntil( |
155 | newRouteName, predicate ?? route, | 119 | newRouteName, predicate ?? route, |
156 | arguments: arguments); | 120 | arguments: arguments); |
157 | } | 121 | } |
158 | - } | 122 | + |
123 | + static bool get isOverlaysOpen => | ||
124 | + (isSnackbarOpen || isDialogOpen || isBottomSheetOpen); | ||
125 | + | ||
126 | + static bool get isOverlaysClosed => | ||
127 | + (!Get.isSnackbarOpen && !Get.isDialogOpen && !Get.isBottomSheetOpen); | ||
159 | 128 | ||
160 | /// It replaces Navigator.pop, but needs no context. | 129 | /// It replaces Navigator.pop, but needs no context. |
161 | - static void back({dynamic result, int id}) { | ||
162 | - if (id == null) { | ||
163 | - key.currentState.pop(result); | ||
164 | - } else { | ||
165 | - global(id).currentState.pop(result); | 130 | + static void back({dynamic result, bool closeOverlays = false, int id}) { |
131 | + if (closeOverlays && isOverlaysOpen) { | ||
132 | + navigator.popUntil((route) { | ||
133 | + return (isOverlaysClosed); | ||
134 | + }); | ||
166 | } | 135 | } |
136 | + global(id).currentState.pop(result); | ||
167 | } | 137 | } |
168 | 138 | ||
169 | /// Experimental API to back from overlay | 139 | /// Experimental API to back from overlay |
@@ -172,12 +142,12 @@ class Get { | @@ -172,12 +142,12 @@ class Get { | ||
172 | } | 142 | } |
173 | 143 | ||
174 | /// It will close as many screens as you define. Times must be> 0; | 144 | /// It will close as many screens as you define. Times must be> 0; |
175 | - static void close(int times) { | 145 | + static void close(int times, [int id]) { |
176 | if ((times == null) || (times < 1)) { | 146 | if ((times == null) || (times < 1)) { |
177 | times = 1; | 147 | times = 1; |
178 | } | 148 | } |
179 | int count = 0; | 149 | int count = 0; |
180 | - void back = key.currentState.popUntil((route) { | 150 | + void back = global(id).currentState.popUntil((route) { |
181 | return count++ == times; | 151 | return count++ == times; |
182 | }); | 152 | }); |
183 | return back; | 153 | return back; |
@@ -191,22 +161,13 @@ class Get { | @@ -191,22 +161,13 @@ class Get { | ||
191 | Transition transition, | 161 | Transition transition, |
192 | bool popGesture, | 162 | bool popGesture, |
193 | int id, | 163 | int id, |
194 | - Duration duration = const Duration(milliseconds: 400)}) { | ||
195 | - if (id == null) { | ||
196 | - return key.currentState.pushReplacement(GetRoute( | ||
197 | - opaque: opaque ?? true, | ||
198 | - page: page, | ||
199 | - popGesture: popGesture ?? _defaultPopGesture, | ||
200 | - transition: transition ?? _defaultTransition, | ||
201 | - transitionDuration: duration)); | ||
202 | - } else { | 164 | + Duration duration}) { |
203 | return global(id).currentState.pushReplacement(GetRoute( | 165 | return global(id).currentState.pushReplacement(GetRoute( |
204 | opaque: opaque ?? true, | 166 | opaque: opaque ?? true, |
205 | page: page, | 167 | page: page, |
206 | popGesture: popGesture ?? _defaultPopGesture, | 168 | popGesture: popGesture ?? _defaultPopGesture, |
207 | transition: transition ?? _defaultTransition, | 169 | transition: transition ?? _defaultTransition, |
208 | - transitionDuration: duration)); | ||
209 | - } | 170 | + transitionDuration: duration ?? _defaultDurationTransition)); |
210 | } | 171 | } |
211 | 172 | ||
212 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context | 173 | /// It replaces Navigator.pushAndRemoveUntil, but needs no context |
@@ -218,16 +179,6 @@ class Get { | @@ -218,16 +179,6 @@ class Get { | ||
218 | Transition transition}) { | 179 | Transition transition}) { |
219 | var route = (Route<dynamic> rota) => false; | 180 | var route = (Route<dynamic> rota) => false; |
220 | 181 | ||
221 | - if (id == null) { | ||
222 | - return key.currentState.pushAndRemoveUntil( | ||
223 | - GetRoute( | ||
224 | - opaque: opaque ?? true, | ||
225 | - popGesture: popGesture ?? _defaultPopGesture, | ||
226 | - page: page, | ||
227 | - transition: transition ?? _defaultTransition, | ||
228 | - ), | ||
229 | - predicate ?? route); | ||
230 | - } else { | ||
231 | return global(id).currentState.pushAndRemoveUntil( | 182 | return global(id).currentState.pushAndRemoveUntil( |
232 | GetRoute( | 183 | GetRoute( |
233 | opaque: opaque ?? true, | 184 | opaque: opaque ?? true, |
@@ -237,59 +188,35 @@ class Get { | @@ -237,59 +188,35 @@ class Get { | ||
237 | ), | 188 | ), |
238 | predicate ?? route); | 189 | predicate ?? route); |
239 | } | 190 | } |
240 | - } | ||
241 | 191 | ||
242 | - /// Show a dialog. You can choose color and opacity of background | 192 | + /// Show a dialog |
243 | static Future<T> dialog<T>( | 193 | static Future<T> dialog<T>( |
244 | Widget child, { | 194 | Widget child, { |
245 | bool barrierDismissible = true, | 195 | bool barrierDismissible = true, |
246 | - // WidgetBuilder builder, | ||
247 | bool useRootNavigator = true, | 196 | bool useRootNavigator = true, |
197 | + RouteSettings routeSettings, | ||
248 | }) { | 198 | }) { |
249 | - assert(child != null); | ||
250 | - assert(useRootNavigator != null); | ||
251 | - final ThemeData theme = | ||
252 | - Theme.of(Get.key.currentContext, shadowThemeOnly: true); | ||
253 | - | ||
254 | - return getShowGeneralDialog( | ||
255 | - pageBuilder: (BuildContext buildContext, Animation<double> animation, | ||
256 | - Animation<double> secondaryAnimation) { | ||
257 | - final Widget pageChild = child; // ?? Builder(builder: builder); | ||
258 | - return SafeArea( | ||
259 | - child: Builder(builder: (BuildContext context) { | ||
260 | - return theme != null | ||
261 | - ? Theme(data: theme, child: pageChild) | ||
262 | - : pageChild; | ||
263 | - }), | ||
264 | - ); | ||
265 | - }, | 199 | + return showDialog( |
266 | barrierDismissible: barrierDismissible, | 200 | barrierDismissible: barrierDismissible, |
267 | - barrierLabel: MaterialLocalizations.of(Get.key.currentContext) | ||
268 | - .modalBarrierDismissLabel, | ||
269 | - barrierColor: Colors.black54, | ||
270 | - transitionDuration: const Duration(milliseconds: 150), | ||
271 | - // transitionBuilder: _buildMaterialDialogTransitions, | ||
272 | useRootNavigator: useRootNavigator, | 201 | useRootNavigator: useRootNavigator, |
202 | + routeSettings: routeSettings, | ||
203 | + context: overlayContext, | ||
204 | + builder: (_) { | ||
205 | + return child; | ||
206 | + }, | ||
273 | ); | 207 | ); |
274 | } | 208 | } |
275 | 209 | ||
276 | static Future<T> defaultDialog<T>( | 210 | static Future<T> defaultDialog<T>( |
277 | - {Color color, | ||
278 | - double opacity = 0.2, | ||
279 | - String title = "Alert dialog", | 211 | + {String title = "Alert dialog", |
280 | Widget content, | 212 | Widget content, |
281 | Widget cancel, | 213 | Widget cancel, |
282 | Widget confirm}) { | 214 | Widget confirm}) { |
283 | - final child = DefaultDialogGet( | ||
284 | - color: color, | ||
285 | - opacity: opacity, | ||
286 | - title: title, | 215 | + return dialog(AlertDialog( |
216 | + title: Text(title, textAlign: TextAlign.center), | ||
287 | content: content, | 217 | content: content, |
288 | - cancel: cancel, | ||
289 | - confirm: confirm, | ||
290 | - ); | ||
291 | - | ||
292 | - return dialog(child); | 218 | + actions: <Widget>[cancel, confirm], |
219 | + )); | ||
293 | } | 220 | } |
294 | 221 | ||
295 | static Future<T> bottomSheet<T>({ | 222 | static Future<T> bottomSheet<T>({ |
@@ -311,7 +238,7 @@ class Get { | @@ -311,7 +238,7 @@ class Get { | ||
311 | assert(isDismissible != null); | 238 | assert(isDismissible != null); |
312 | assert(enableDrag != null); | 239 | assert(enableDrag != null); |
313 | 240 | ||
314 | - return Get.key.currentState.push<T>(GetModalBottomSheetRoute<T>( | 241 | + return navigator.push<T>(GetModalBottomSheetRoute<T>( |
315 | builder: builder, | 242 | builder: builder, |
316 | theme: Theme.of(Get.key.currentContext, shadowThemeOnly: true), | 243 | theme: Theme.of(Get.key.currentContext, shadowThemeOnly: true), |
317 | isScrollControlled: isScrollControlled, | 244 | isScrollControlled: isScrollControlled, |
@@ -421,6 +348,8 @@ class Get { | @@ -421,6 +348,8 @@ class Get { | ||
421 | {bool enableLog, | 348 | {bool enableLog, |
422 | bool defaultPopGesture, | 349 | bool defaultPopGesture, |
423 | bool defaultOpaqueRoute, | 350 | bool defaultOpaqueRoute, |
351 | + Duration defaultDurationTransition, | ||
352 | + bool defaultGlobalState, | ||
424 | Transition defaultTransition}) { | 353 | Transition defaultTransition}) { |
425 | if (enableLog != null) { | 354 | if (enableLog != null) { |
426 | _enableLog = enableLog; | 355 | _enableLog = enableLog; |
@@ -434,6 +363,14 @@ class Get { | @@ -434,6 +363,14 @@ class Get { | ||
434 | if (defaultTransition != null) { | 363 | if (defaultTransition != null) { |
435 | _defaultTransition = defaultTransition; | 364 | _defaultTransition = defaultTransition; |
436 | } | 365 | } |
366 | + | ||
367 | + if (defaultDurationTransition != null) { | ||
368 | + _defaultDurationTransition = defaultDurationTransition; | ||
369 | + } | ||
370 | + | ||
371 | + if (defaultGlobalState != null) { | ||
372 | + _defaultGlobalState = defaultGlobalState; | ||
373 | + } | ||
437 | } | 374 | } |
438 | 375 | ||
439 | static Map<int, GlobalKey<NavigatorState>> _keys = {}; | 376 | static Map<int, GlobalKey<NavigatorState>> _keys = {}; |
@@ -443,14 +380,17 @@ class Get { | @@ -443,14 +380,17 @@ class Get { | ||
443 | return _keys[key]; | 380 | return _keys[key]; |
444 | } | 381 | } |
445 | 382 | ||
446 | - static GlobalKey<NavigatorState> global(int key) { | ||
447 | - if (!_keys.containsKey(key)) { | 383 | + static GlobalKey<NavigatorState> global(int k) { |
384 | + if (k == null) { | ||
385 | + return key; | ||
386 | + } | ||
387 | + if (!_keys.containsKey(k)) { | ||
448 | throw 'route id not found'; | 388 | throw 'route id not found'; |
449 | } | 389 | } |
450 | - final recoverKey = _keys[key]; | ||
451 | - return recoverKey; | 390 | + return _keys[k]; |
452 | } | 391 | } |
453 | 392 | ||
393 | + //////////// INSTANCE MANAGER | ||
454 | static Map<dynamic, dynamic> _singl = {}; | 394 | static Map<dynamic, dynamic> _singl = {}; |
455 | 395 | ||
456 | /// Register a singleton instance of your class | 396 | /// Register a singleton instance of your class |
@@ -468,10 +408,13 @@ class Get { | @@ -468,10 +408,13 @@ class Get { | ||
468 | return true; | 408 | return true; |
469 | } | 409 | } |
470 | 410 | ||
411 | + /// check if instance is registred | ||
412 | + static bool isRegistred<T>() => _singl.containsKey(T); | ||
413 | + | ||
471 | /// Recover a singleton instance of your class | 414 | /// Recover a singleton instance of your class |
472 | - static T find<T>(T key) { | 415 | + static T find<T>() { |
473 | if (!_singl.containsKey(T)) { | 416 | if (!_singl.containsKey(T)) { |
474 | - throw 'key id not found'; | 417 | + throw 'key id ${T.runtimeType} not found'; |
475 | } | 418 | } |
476 | final recoverKey = _singl[T]; | 419 | final recoverKey = _singl[T]; |
477 | return recoverKey; | 420 | return recoverKey; |
@@ -480,15 +423,30 @@ class Get { | @@ -480,15 +423,30 @@ class Get { | ||
480 | /// give access to Routing API from GetObserver | 423 | /// give access to Routing API from GetObserver |
481 | static Routing get routing => _routing; | 424 | static Routing get routing => _routing; |
482 | 425 | ||
426 | + static RouteSettings get routeSettings => _settings; | ||
427 | + | ||
483 | static Routing _routing; | 428 | static Routing _routing; |
484 | 429 | ||
430 | + static Map<String, String> _parameters = {}; | ||
431 | + | ||
432 | + static setParameter(Map<String, String> param) { | ||
433 | + _parameters = param; | ||
434 | + } | ||
435 | + | ||
485 | static setRouting(Routing rt) { | 436 | static setRouting(Routing rt) { |
486 | _routing = rt; | 437 | _routing = rt; |
487 | } | 438 | } |
488 | 439 | ||
440 | + static setSettings(RouteSettings settings) { | ||
441 | + _settings = settings; | ||
442 | + } | ||
443 | + | ||
489 | /// give current arguments | 444 | /// give current arguments |
490 | static get arguments => _routing.args; | 445 | static get arguments => _routing.args; |
491 | 446 | ||
447 | + /// give current arguments | ||
448 | + static Map<String, String> get parameters => _parameters; | ||
449 | + | ||
492 | /// give arguments from previous route | 450 | /// give arguments from previous route |
493 | static get previousArguments => _routing.previousArgs; | 451 | static get previousArguments => _routing.previousArgs; |
494 | 452 | ||
@@ -513,6 +471,13 @@ class Get { | @@ -513,6 +471,13 @@ class Get { | ||
513 | /// check if log is enable | 471 | /// check if log is enable |
514 | static bool get isLogEnable => _enableLog; | 472 | static bool get isLogEnable => _enableLog; |
515 | 473 | ||
474 | + /// default duration of transition animation | ||
475 | + /// default duration work only API 2.0 | ||
476 | + static Duration get defaultDurationTransition => _defaultDurationTransition; | ||
477 | + | ||
478 | + /// give global state of all GetState by default | ||
479 | + static bool get defaultGlobalState => _defaultGlobalState; | ||
480 | + | ||
516 | /// check if popGesture is enable | 481 | /// check if popGesture is enable |
517 | static bool get isPopGestureEnable => _defaultPopGesture; | 482 | static bool get isPopGestureEnable => _defaultPopGesture; |
518 | 483 |
lib/src/root/root_widget.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | +import 'package:get/get.dart'; | ||
3 | +import 'package:get/src/routes/utils/parse_arguments.dart'; | ||
4 | + | ||
5 | +class GetMaterialApp extends StatefulWidget { | ||
6 | + const GetMaterialApp({ | ||
7 | + Key key, | ||
8 | + this.navigatorKey, | ||
9 | + this.home, | ||
10 | + this.routes = const <String, WidgetBuilder>{}, | ||
11 | + this.initialRoute, | ||
12 | + this.onGenerateRoute, | ||
13 | + this.onGenerateInitialRoutes, | ||
14 | + this.onUnknownRoute, | ||
15 | + this.navigatorObservers = const <NavigatorObserver>[], | ||
16 | + this.builder, | ||
17 | + this.title = '', | ||
18 | + this.onGenerateTitle, | ||
19 | + this.color, | ||
20 | + this.theme, | ||
21 | + this.darkTheme, | ||
22 | + this.themeMode = ThemeMode.system, | ||
23 | + this.locale, | ||
24 | + this.localizationsDelegates, | ||
25 | + this.localeListResolutionCallback, | ||
26 | + this.localeResolutionCallback, | ||
27 | + this.supportedLocales = const <Locale>[Locale('en', 'US')], | ||
28 | + this.debugShowMaterialGrid = false, | ||
29 | + this.showPerformanceOverlay = false, | ||
30 | + this.checkerboardRasterCacheImages = false, | ||
31 | + this.checkerboardOffscreenLayers = false, | ||
32 | + this.showSemanticsDebugger = false, | ||
33 | + this.debugShowCheckedModeBanner = true, | ||
34 | + this.shortcuts, | ||
35 | + this.routingCallback, | ||
36 | + this.defaultTransition, | ||
37 | + this.actions, | ||
38 | + this.opaqueRoute, | ||
39 | + this.enableLog, | ||
40 | + this.popGesture, | ||
41 | + this.transitionDuration, | ||
42 | + this.defaultGlobalState, | ||
43 | + this.namedRoutes, | ||
44 | + this.unknownRoute, | ||
45 | + }) : assert(routes != null), | ||
46 | + assert(navigatorObservers != null), | ||
47 | + assert(title != null), | ||
48 | + assert(debugShowMaterialGrid != null), | ||
49 | + assert(showPerformanceOverlay != null), | ||
50 | + assert(checkerboardRasterCacheImages != null), | ||
51 | + assert(checkerboardOffscreenLayers != null), | ||
52 | + assert(showSemanticsDebugger != null), | ||
53 | + assert(debugShowCheckedModeBanner != null), | ||
54 | + super(key: key); | ||
55 | + | ||
56 | + final GlobalKey<NavigatorState> navigatorKey; | ||
57 | + final Widget home; | ||
58 | + final Map<String, WidgetBuilder> routes; | ||
59 | + final String initialRoute; | ||
60 | + final RouteFactory onGenerateRoute; | ||
61 | + final InitialRouteListFactory onGenerateInitialRoutes; | ||
62 | + final RouteFactory onUnknownRoute; | ||
63 | + final List<NavigatorObserver> navigatorObservers; | ||
64 | + final TransitionBuilder builder; | ||
65 | + final String title; | ||
66 | + final GenerateAppTitle onGenerateTitle; | ||
67 | + final ThemeData theme; | ||
68 | + final ThemeData darkTheme; | ||
69 | + final ThemeMode themeMode; | ||
70 | + final Color color; | ||
71 | + final Locale locale; | ||
72 | + final Iterable<LocalizationsDelegate<dynamic>> localizationsDelegates; | ||
73 | + final LocaleListResolutionCallback localeListResolutionCallback; | ||
74 | + final LocaleResolutionCallback localeResolutionCallback; | ||
75 | + final Iterable<Locale> supportedLocales; | ||
76 | + final bool showPerformanceOverlay; | ||
77 | + final bool checkerboardRasterCacheImages; | ||
78 | + final bool checkerboardOffscreenLayers; | ||
79 | + final bool showSemanticsDebugger; | ||
80 | + final bool debugShowCheckedModeBanner; | ||
81 | + final Map<LogicalKeySet, Intent> shortcuts; | ||
82 | + final Map<LocalKey, ActionFactory> actions; | ||
83 | + final bool debugShowMaterialGrid; | ||
84 | + final Function(Routing) routingCallback; | ||
85 | + final Transition defaultTransition; | ||
86 | + final bool opaqueRoute; | ||
87 | + final bool enableLog; | ||
88 | + final bool popGesture; | ||
89 | + final Duration transitionDuration; | ||
90 | + final bool defaultGlobalState; | ||
91 | + final Map<String, GetRoute> namedRoutes; | ||
92 | + final GetRoute unknownRoute; | ||
93 | + | ||
94 | + @override | ||
95 | + _GetMaterialAppState createState() => _GetMaterialAppState(); | ||
96 | +} | ||
97 | + | ||
98 | +class _GetMaterialAppState extends State<GetMaterialApp> { | ||
99 | + ParseRoute parse = ParseRoute(); | ||
100 | + @override | ||
101 | + void initState() { | ||
102 | + if (widget.namedRoutes != null) { | ||
103 | + widget.namedRoutes.forEach((key, value) { | ||
104 | + parse.addRoute(key); | ||
105 | + }); | ||
106 | + } | ||
107 | + Get.config( | ||
108 | + enableLog: widget.enableLog ?? Get.isLogEnable, | ||
109 | + defaultTransition: widget.defaultTransition ?? Get.defaultTransition, | ||
110 | + defaultOpaqueRoute: widget.opaqueRoute ?? Get.isOpaqueRouteDefault, | ||
111 | + defaultPopGesture: widget.popGesture ?? Get.isPopGestureEnable, | ||
112 | + defaultDurationTransition: | ||
113 | + widget.transitionDuration ?? Get.defaultDurationTransition, | ||
114 | + defaultGlobalState: widget.defaultGlobalState ?? Get.defaultGlobalState, | ||
115 | + ); | ||
116 | + super.initState(); | ||
117 | + } | ||
118 | + | ||
119 | + Route<dynamic> namedRoutesGenerate(RouteSettings settings) { | ||
120 | + Get.setSettings(settings); | ||
121 | + final parsedString = parse.split(settings.name); | ||
122 | + String settingsname = parsedString.route; | ||
123 | + Map<String, GetRoute> newNamedRoutes = {}; | ||
124 | + | ||
125 | + widget.namedRoutes.forEach((key, value) { | ||
126 | + String newName = parse.split(key).route; | ||
127 | + newNamedRoutes.addAll({newName: value}); | ||
128 | + }); | ||
129 | + | ||
130 | + if (newNamedRoutes.containsKey(settingsname)) { | ||
131 | + Get.setParameter(parsedString.parameters); | ||
132 | + return GetRoute( | ||
133 | + page: newNamedRoutes[settingsname].page, | ||
134 | + title: newNamedRoutes[settingsname].title, | ||
135 | + parameter: parsedString.parameters, | ||
136 | + settings: | ||
137 | + RouteSettings(name: settings.name, arguments: settings.arguments), | ||
138 | + maintainState: newNamedRoutes[settingsname].maintainState, | ||
139 | + curve: newNamedRoutes[settingsname].curve, | ||
140 | + alignment: newNamedRoutes[settingsname].alignment, | ||
141 | + opaque: newNamedRoutes[settingsname].opaque, | ||
142 | + transitionDuration: (widget.transitionDuration == null | ||
143 | + ? newNamedRoutes[settingsname].transitionDuration | ||
144 | + : widget.transitionDuration), | ||
145 | + transition: newNamedRoutes[settingsname].transition, | ||
146 | + popGesture: newNamedRoutes[settingsname].popGesture, | ||
147 | + fullscreenDialog: newNamedRoutes[settingsname].fullscreenDialog, | ||
148 | + ); | ||
149 | + } else { | ||
150 | + return (widget.unknownRoute ?? | ||
151 | + GetRoute( | ||
152 | + page: Scaffold( | ||
153 | + body: Center( | ||
154 | + child: Text("Route not found :("), | ||
155 | + ), | ||
156 | + ))); | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
160 | + @override | ||
161 | + Widget build(BuildContext context) { | ||
162 | + return MaterialApp( | ||
163 | + navigatorKey: (widget.navigatorKey == null | ||
164 | + ? Get.key | ||
165 | + : Get.addKey(widget.navigatorKey)), | ||
166 | + home: widget.home, | ||
167 | + routes: widget.routes ?? const <String, WidgetBuilder>{}, | ||
168 | + initialRoute: widget.initialRoute, | ||
169 | + onGenerateRoute: (widget.namedRoutes == null | ||
170 | + ? widget.onGenerateRoute | ||
171 | + : namedRoutesGenerate), | ||
172 | + onGenerateInitialRoutes: widget.onGenerateInitialRoutes, | ||
173 | + onUnknownRoute: widget.onUnknownRoute, | ||
174 | + navigatorObservers: (widget.navigatorObservers == null | ||
175 | + ? <NavigatorObserver>[GetObserver(widget.routingCallback)] | ||
176 | + : <NavigatorObserver>[GetObserver(widget.routingCallback)] | ||
177 | + ..addAll(widget.navigatorObservers)), | ||
178 | + builder: widget.builder, | ||
179 | + title: widget.title ?? '', | ||
180 | + onGenerateTitle: widget.onGenerateTitle, | ||
181 | + color: widget.color, | ||
182 | + theme: widget.theme, | ||
183 | + darkTheme: widget.darkTheme, | ||
184 | + themeMode: widget.themeMode ?? ThemeMode.system, | ||
185 | + locale: widget.locale, | ||
186 | + localizationsDelegates: widget.localizationsDelegates, | ||
187 | + localeListResolutionCallback: widget.localeListResolutionCallback, | ||
188 | + localeResolutionCallback: widget.localeResolutionCallback, | ||
189 | + supportedLocales: | ||
190 | + widget.supportedLocales ?? const <Locale>[Locale('en', 'US')], | ||
191 | + debugShowMaterialGrid: widget.debugShowMaterialGrid ?? false, | ||
192 | + showPerformanceOverlay: widget.showPerformanceOverlay ?? false, | ||
193 | + checkerboardRasterCacheImages: | ||
194 | + widget.checkerboardRasterCacheImages ?? false, | ||
195 | + checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers ?? false, | ||
196 | + showSemanticsDebugger: widget.showSemanticsDebugger ?? false, | ||
197 | + debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner ?? true, | ||
198 | + shortcuts: widget.shortcuts, | ||
199 | + actions: widget.actions, | ||
200 | + ); | ||
201 | + } | ||
202 | +} |
1 | -import 'dart:math' as math; | ||
2 | -import 'dart:ui' as ui; | ||
3 | - | ||
4 | -import 'package:flutter/material.dart'; | ||
5 | -import 'package:flutter/scheduler.dart'; | ||
6 | - | ||
7 | -class RippleBackdropAnimatePage extends StatefulWidget { | ||
8 | - const RippleBackdropAnimatePage({ | ||
9 | - Key key, | ||
10 | - this.child, | ||
11 | - this.childFade = false, | ||
12 | - this.duration = 300, | ||
13 | - this.blurRadius = 15.0, | ||
14 | - this.bottomButton, | ||
15 | - this.bottomHeight = kBottomNavigationBarHeight, | ||
16 | - this.bottomButtonRotate = true, | ||
17 | - this.bottomButtonRotateDegree = 45.0, | ||
18 | - }) : super(key: key); | ||
19 | - | ||
20 | - /// Child for page. | ||
21 | - final Widget child; | ||
22 | - | ||
23 | - /// When enabled, [child] will fade in when animation is going and fade out when popping. | ||
24 | - /// [false] is by default. | ||
25 | - final bool childFade; | ||
26 | - | ||
27 | - /// Animation's duration, | ||
28 | - /// including [Navigator.push], [Navigator.pop]. | ||
29 | - final int duration; | ||
30 | - | ||
31 | - /// Blur radius for [BackdropFilter]. | ||
32 | - final double blurRadius; | ||
33 | - | ||
34 | - /// [Widget] for bottom of the page. | ||
35 | - final Widget bottomButton; | ||
36 | - | ||
37 | - /// The height which [bottomButton] will occupy. | ||
38 | - /// [kBottomNavigationBarHeight] is by default. | ||
39 | - final double bottomHeight; | ||
40 | - | ||
41 | - /// When enabled, [bottomButton] will rotate when to animation is going. | ||
42 | - /// [true] is by default. | ||
43 | - final bool bottomButtonRotate; | ||
44 | - | ||
45 | - /// The degree which [bottomButton] will rotate. | ||
46 | - /// 45.0 is by default. | ||
47 | - final double bottomButtonRotateDegree; | ||
48 | - | ||
49 | - @override | ||
50 | - _RippleBackdropAnimatePageState createState() => | ||
51 | - _RippleBackdropAnimatePageState(); | ||
52 | -} | ||
53 | - | ||
54 | -class _RippleBackdropAnimatePageState extends State<RippleBackdropAnimatePage> | ||
55 | - with TickerProviderStateMixin { | ||
56 | - /// Boolean to prevent duplicate pop. | ||
57 | - bool _popping = false; | ||
58 | - | ||
59 | - /// Animation. | ||
60 | - int _animateDuration; | ||
61 | - double _backdropFilterSize = 0.0; | ||
62 | - double _popButtonOpacity = 0.0; | ||
63 | - double _popButtonRotateAngle = 0.0; | ||
64 | - Animation<double> _backDropFilterAnimation; | ||
65 | - AnimationController _backDropFilterController; | ||
66 | - Animation<double> _popButtonAnimation; | ||
67 | - AnimationController _popButtonController; | ||
68 | - Animation<double> _popButtonOpacityAnimation; | ||
69 | - AnimationController _popButtonOpacityController; | ||
70 | - | ||
71 | - @override | ||
72 | - void initState() { | ||
73 | - _animateDuration = widget.duration; | ||
74 | - SchedulerBinding.instance | ||
75 | - .addPostFrameCallback((_) => backDropFilterAnimate(context, true)); | ||
76 | - super.initState(); | ||
77 | - } | ||
78 | - | ||
79 | - @override | ||
80 | - void dispose() { | ||
81 | - _backDropFilterController?.dispose(); | ||
82 | - _popButtonController?.dispose(); | ||
83 | - super.dispose(); | ||
84 | - } | ||
85 | - | ||
86 | - double pythagoreanTheorem(double short, double long) { | ||
87 | - return math.sqrt(math.pow(short, 2) + math.pow(long, 2)); | ||
88 | - } | ||
89 | - | ||
90 | - void popButtonAnimate(context, bool forward) { | ||
91 | - if (!forward) { | ||
92 | - _popButtonController?.stop(); | ||
93 | - _popButtonOpacityController?.stop(); | ||
94 | - } | ||
95 | - final double rotateDegree = | ||
96 | - widget.bottomButtonRotateDegree * (math.pi / 180) * 3; | ||
97 | - | ||
98 | - _popButtonOpacityController = _popButtonController = AnimationController( | ||
99 | - duration: Duration(milliseconds: _animateDuration), | ||
100 | - vsync: this, | ||
101 | - ); | ||
102 | - Animation _popButtonCurve = CurvedAnimation( | ||
103 | - parent: _popButtonController, | ||
104 | - curve: Curves.easeInOut, | ||
105 | - ); | ||
106 | - _popButtonAnimation = Tween( | ||
107 | - begin: forward ? 0.0 : _popButtonRotateAngle, | ||
108 | - end: forward ? rotateDegree : 0.0, | ||
109 | - ).animate(_popButtonCurve) | ||
110 | - ..addListener(() { | ||
111 | - setState(() { | ||
112 | - _popButtonRotateAngle = _popButtonAnimation.value; | ||
113 | - }); | ||
114 | - }); | ||
115 | - _popButtonOpacityAnimation = Tween( | ||
116 | - begin: forward ? 0.0 : _popButtonOpacity, | ||
117 | - end: forward ? 1.0 : 0.0, | ||
118 | - ).animate(_popButtonCurve) | ||
119 | - ..addListener(() { | ||
120 | - setState(() { | ||
121 | - _popButtonOpacity = _popButtonOpacityAnimation.value; | ||
122 | - }); | ||
123 | - }); | ||
124 | - _popButtonController.forward(); | ||
125 | - _popButtonOpacityController.forward(); | ||
126 | - } | ||
127 | - | ||
128 | - Future backDropFilterAnimate(BuildContext context, bool forward) async { | ||
129 | - final MediaQueryData m = MediaQuery.of(context); | ||
130 | - final Size s = m.size; | ||
131 | - final double r = | ||
132 | - pythagoreanTheorem(s.width, s.height * 2 + m.padding.top) / 2; | ||
133 | - if (!forward) _backDropFilterController?.stop(); | ||
134 | - popButtonAnimate(context, forward); | ||
135 | - | ||
136 | - _backDropFilterController = AnimationController( | ||
137 | - duration: Duration(milliseconds: _animateDuration), | ||
138 | - vsync: this, | ||
139 | - ); | ||
140 | - Animation _backDropFilterCurve = CurvedAnimation( | ||
141 | - parent: _backDropFilterController, | ||
142 | - curve: forward ? Curves.easeInOut : Curves.easeIn, | ||
143 | - ); | ||
144 | - _backDropFilterAnimation = Tween( | ||
145 | - begin: forward ? 0.0 : _backdropFilterSize, | ||
146 | - end: forward ? r * 2 : 0.0, | ||
147 | - ).animate(_backDropFilterCurve) | ||
148 | - ..addListener(() { | ||
149 | - setState(() { | ||
150 | - _backdropFilterSize = _backDropFilterAnimation.value; | ||
151 | - }); | ||
152 | - }); | ||
153 | - await _backDropFilterController.forward(); | ||
154 | - } | ||
155 | - | ||
156 | - Widget popButton() { | ||
157 | - Widget button = widget.bottomButton ?? Icon(Icons.add, color: Colors.grey); | ||
158 | - if (widget.bottomButtonRotate) { | ||
159 | - button = Transform.rotate( | ||
160 | - angle: _popButtonRotateAngle, | ||
161 | - child: button, | ||
162 | - ); | ||
163 | - } | ||
164 | - button = Opacity( | ||
165 | - opacity: _popButtonOpacity, | ||
166 | - child: SizedBox( | ||
167 | - width: widget.bottomHeight, | ||
168 | - height: widget.bottomHeight, | ||
169 | - child: Center( | ||
170 | - child: GestureDetector( | ||
171 | - behavior: HitTestBehavior.opaque, | ||
172 | - child: button, | ||
173 | - onTap: willPop, | ||
174 | - ), | ||
175 | - ), | ||
176 | - ), | ||
177 | - ); | ||
178 | - | ||
179 | - return button; | ||
180 | - } | ||
181 | - | ||
182 | - Widget wrapper(context, {Widget child}) { | ||
183 | - final MediaQueryData m = MediaQuery.of(context); | ||
184 | - final Size s = m.size; | ||
185 | - final double r = | ||
186 | - pythagoreanTheorem(s.width, s.height * 2 + m.padding.top) / 2; | ||
187 | - final double topOverflow = r - s.height; | ||
188 | - final double horizontalOverflow = r - s.width; | ||
189 | - | ||
190 | - return Stack( | ||
191 | - overflow: Overflow.visible, | ||
192 | - children: <Widget>[ | ||
193 | - Positioned( | ||
194 | - left: -horizontalOverflow, | ||
195 | - right: -horizontalOverflow, | ||
196 | - top: -topOverflow, | ||
197 | - bottom: -r, | ||
198 | - child: GestureDetector( | ||
199 | - behavior: HitTestBehavior.opaque, | ||
200 | - onTap: willPop, | ||
201 | - child: Center( | ||
202 | - child: SizedBox( | ||
203 | - width: _backdropFilterSize, | ||
204 | - height: _backdropFilterSize, | ||
205 | - child: ClipRRect( | ||
206 | - borderRadius: BorderRadius.circular(r * 2), | ||
207 | - child: BackdropFilter( | ||
208 | - filter: ui.ImageFilter.blur( | ||
209 | - sigmaX: widget.blurRadius, | ||
210 | - sigmaY: widget.blurRadius, | ||
211 | - ), | ||
212 | - child: Text(" "), | ||
213 | - ), | ||
214 | - ), | ||
215 | - ), | ||
216 | - ), | ||
217 | - ), | ||
218 | - ), | ||
219 | - Align( | ||
220 | - alignment: Alignment.topCenter, | ||
221 | - child: Container( | ||
222 | - margin: EdgeInsets.only(top: topOverflow + 10), | ||
223 | - width: s.width, | ||
224 | - height: s.height, | ||
225 | - constraints: BoxConstraints( | ||
226 | - maxWidth: s.width, | ||
227 | - maxHeight: s.height, | ||
228 | - ), | ||
229 | - child: Column( | ||
230 | - mainAxisAlignment: MainAxisAlignment.end, | ||
231 | - children: <Widget>[ | ||
232 | - Expanded( | ||
233 | - child: Opacity( | ||
234 | - opacity: widget.childFade ? _popButtonOpacity : 1.0, | ||
235 | - child: child, | ||
236 | - ), | ||
237 | - ), | ||
238 | - popButton(), | ||
239 | - ], | ||
240 | - ), | ||
241 | - ), | ||
242 | - ), | ||
243 | - ], | ||
244 | - ); | ||
245 | - } | ||
246 | - | ||
247 | - Future<bool> willPop() async { | ||
248 | - await backDropFilterAnimate(context, false); | ||
249 | - if (!_popping) { | ||
250 | - _popping = true; | ||
251 | - await Future.delayed(Duration(milliseconds: _animateDuration), () { | ||
252 | - Navigator.of(context).pop(); | ||
253 | - }); | ||
254 | - } | ||
255 | - return null; | ||
256 | - } | ||
257 | - | ||
258 | - @override | ||
259 | - Widget build(BuildContext context) { | ||
260 | - return Scaffold( | ||
261 | - backgroundColor: Colors.transparent, | ||
262 | - body: WillPopScope( | ||
263 | - onWillPop: willPop, | ||
264 | - child: wrapper( | ||
265 | - context, | ||
266 | - child: widget.child, | ||
267 | - ), | ||
268 | - ), | ||
269 | - ); | ||
270 | - } | ||
271 | -} |
1 | -import 'package:flutter/material.dart'; | ||
2 | - | ||
3 | -class TransparentRoute extends PageRoute<void> { | ||
4 | - TransparentRoute({ | ||
5 | - @required this.builder, | ||
6 | - RouteSettings settings, | ||
7 | - }) : assert(builder != null), | ||
8 | - super(settings: settings, fullscreenDialog: false); | ||
9 | - | ||
10 | - final WidgetBuilder builder; | ||
11 | - | ||
12 | - @override | ||
13 | - bool get opaque => false; | ||
14 | - @override | ||
15 | - Color get barrierColor => null; | ||
16 | - @override | ||
17 | - String get barrierLabel => null; | ||
18 | - @override | ||
19 | - bool get maintainState => true; | ||
20 | - @override | ||
21 | - Duration get transitionDuration => Duration.zero; | ||
22 | - | ||
23 | - @override | ||
24 | - Widget buildPage(BuildContext context, Animation<double> animation, | ||
25 | - Animation<double> secondaryAnimation) { | ||
26 | - final result = builder(context); | ||
27 | - return Semantics( | ||
28 | - scopesRoute: true, | ||
29 | - explicitChildNodes: true, | ||
30 | - child: result, | ||
31 | - ); | ||
32 | - } | ||
33 | -} |
@@ -19,8 +19,6 @@ const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds. | @@ -19,8 +19,6 @@ const int _kMaxDroppedSwipePageForwardAnimationTime = 800; // Milliseconds. | ||
19 | const int _kMaxPageBackAnimationTime = 300; | 19 | const int _kMaxPageBackAnimationTime = 300; |
20 | 20 | ||
21 | class GetRoute<T> extends PageRoute<T> { | 21 | class GetRoute<T> extends PageRoute<T> { |
22 | - /// Creates a page route for use in an iOS designed app. | ||
23 | - /// | ||
24 | /// The [builder], [maintainState], and [fullscreenDialog] arguments must not | 22 | /// The [builder], [maintainState], and [fullscreenDialog] arguments must not |
25 | /// be null. | 23 | /// be null. |
26 | GetRoute({ | 24 | GetRoute({ |
@@ -30,6 +28,7 @@ class GetRoute<T> extends PageRoute<T> { | @@ -30,6 +28,7 @@ class GetRoute<T> extends PageRoute<T> { | ||
30 | this.maintainState = true, | 28 | this.maintainState = true, |
31 | this.curve = Curves.linear, | 29 | this.curve = Curves.linear, |
32 | this.alignment, | 30 | this.alignment, |
31 | + this.parameter, | ||
33 | this.opaque = true, | 32 | this.opaque = true, |
34 | this.transitionDuration = const Duration(milliseconds: 400), | 33 | this.transitionDuration = const Duration(milliseconds: 400), |
35 | this.popGesture, | 34 | this.popGesture, |
@@ -49,6 +48,8 @@ class GetRoute<T> extends PageRoute<T> { | @@ -49,6 +48,8 @@ class GetRoute<T> extends PageRoute<T> { | ||
49 | 48 | ||
50 | // final Duration duration; | 49 | // final Duration duration; |
51 | 50 | ||
51 | + final Map<String, String> parameter; | ||
52 | + | ||
52 | final String title; | 53 | final String title; |
53 | 54 | ||
54 | final Transition transition; | 55 | final Transition transition; |
@@ -231,7 +232,6 @@ class GetRoute<T> extends PageRoute<T> { | @@ -231,7 +232,6 @@ class GetRoute<T> extends PageRoute<T> { | ||
231 | Animation<double> secondaryAnimation, | 232 | Animation<double> secondaryAnimation, |
232 | Widget child, | 233 | Widget child, |
233 | Transition tr, | 234 | Transition tr, |
234 | - Duration duration, | ||
235 | Curve curve, | 235 | Curve curve, |
236 | Alignment alignment, | 236 | Alignment alignment, |
237 | ) { | 237 | ) { |
@@ -472,7 +472,6 @@ class GetRoute<T> extends PageRoute<T> { | @@ -472,7 +472,6 @@ class GetRoute<T> extends PageRoute<T> { | ||
472 | secondaryAnimation, | 472 | secondaryAnimation, |
473 | child, | 473 | child, |
474 | transition, | 474 | transition, |
475 | - transitionDuration, | ||
476 | curve, | 475 | curve, |
477 | alignment); | 476 | alignment); |
478 | } | 477 | } |
@@ -100,6 +100,7 @@ class GetObserver extends NavigatorObserver { | @@ -100,6 +100,7 @@ class GetObserver extends NavigatorObserver { | ||
100 | void didReplace({Route newRoute, Route oldRoute}) { | 100 | void didReplace({Route newRoute, Route oldRoute}) { |
101 | super.didReplace(newRoute: newRoute, oldRoute: oldRoute); | 101 | super.didReplace(newRoute: newRoute, oldRoute: oldRoute); |
102 | if (Get.isLogEnable) print("[REPLACE ROUTE] ${oldRoute?.settings?.name}"); | 102 | if (Get.isLogEnable) print("[REPLACE ROUTE] ${oldRoute?.settings?.name}"); |
103 | + if (Get.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}"); | ||
103 | 104 | ||
104 | final routeSend = Routing( | 105 | final routeSend = Routing( |
105 | removed: null, // add '${oldRoute?.settings?.name}' or remain null ??? | 106 | removed: null, // add '${oldRoute?.settings?.name}' or remain null ??? |
lib/src/routes/utils/parse_arguments.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | + | ||
3 | +class ParseRoute { | ||
4 | + final List<ParseRouteSplit> _routeSplits = <ParseRouteSplit>[]; | ||
5 | + | ||
6 | + void addRoute(String routePath) { | ||
7 | + String path = routePath; | ||
8 | + | ||
9 | + if (path == Navigator.defaultRouteName) { | ||
10 | + var routeSplit = ParseRouteSplit(path, ParseRouteSplitType.component); | ||
11 | + routeSplit.routes = [routePath]; | ||
12 | + _routeSplits.add(routeSplit); | ||
13 | + return; | ||
14 | + } | ||
15 | + if (path.startsWith("/")) { | ||
16 | + path = path.substring(1); | ||
17 | + } | ||
18 | + List<String> pathComponents = path.split('/'); | ||
19 | + ParseRouteSplit parent; | ||
20 | + for (int i = 0; i < pathComponents.length; i++) { | ||
21 | + String component = pathComponents[i]; | ||
22 | + ParseRouteSplit routeSplit = _routeSplitForComponent(component, parent); | ||
23 | + if (routeSplit == null) { | ||
24 | + ParseRouteSplitType type = _typeForComponent(component); | ||
25 | + routeSplit = ParseRouteSplit(component, type); | ||
26 | + routeSplit.parent = parent; | ||
27 | + if (parent == null) { | ||
28 | + _routeSplits.add(routeSplit); | ||
29 | + } else { | ||
30 | + parent.routeSplits.add(routeSplit); | ||
31 | + } | ||
32 | + } | ||
33 | + if (i == pathComponents.length - 1) { | ||
34 | + if (routeSplit.routes == null) { | ||
35 | + routeSplit.routes = [routePath]; | ||
36 | + } else { | ||
37 | + routeSplit.routes.add(routePath); | ||
38 | + } | ||
39 | + } | ||
40 | + parent = routeSplit; | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + AppRouteMatch split(String path) { | ||
45 | + String usePath = path; | ||
46 | + if (usePath.startsWith("/")) { | ||
47 | + usePath = path.substring(1); | ||
48 | + } | ||
49 | + List<String> components = usePath.split("/"); | ||
50 | + if (path == Navigator.defaultRouteName) { | ||
51 | + components = ["/"]; | ||
52 | + } | ||
53 | + | ||
54 | + Map<ParseRouteSplit, ParseRouteSplitMatch> routeSplitMatches = | ||
55 | + <ParseRouteSplit, ParseRouteSplitMatch>{}; | ||
56 | + List<ParseRouteSplit> routeSplitsToCheck = _routeSplits; | ||
57 | + for (String checkComponent in components) { | ||
58 | + Map<ParseRouteSplit, ParseRouteSplitMatch> currentMatches = | ||
59 | + <ParseRouteSplit, ParseRouteSplitMatch>{}; | ||
60 | + List<ParseRouteSplit> nextrouteSplits = <ParseRouteSplit>[]; | ||
61 | + for (ParseRouteSplit routeSplit in routeSplitsToCheck) { | ||
62 | + String pathPart = checkComponent; | ||
63 | + Map<String, String> queryMap = {}; | ||
64 | + if (checkComponent.contains("?") && !checkComponent.contains("=")) { | ||
65 | + var splitParam = checkComponent.split("?"); | ||
66 | + pathPart = splitParam[0]; | ||
67 | + queryMap = {pathPart: splitParam[1]}; | ||
68 | + } else if (checkComponent.contains("?")) { | ||
69 | + var splitParam = checkComponent.split("?"); | ||
70 | + var splitParam2 = splitParam[1].split("="); | ||
71 | + if (!splitParam2[1].contains("&")) { | ||
72 | + pathPart = splitParam[0]; | ||
73 | + queryMap = {splitParam2[0]: splitParam2[1]}; | ||
74 | + } else { | ||
75 | + pathPart = splitParam[0]; | ||
76 | + final segunda = splitParam[1]; | ||
77 | + var other = segunda.split(RegExp(r"[&,=]")); | ||
78 | + for (var i = 0; i < (other.length - 1); i++) { | ||
79 | + bool impar = (i % 2 == 0); | ||
80 | + if (impar) { | ||
81 | + queryMap.addAll({other[0 + i]: other[1 + i]}); | ||
82 | + } | ||
83 | + } | ||
84 | + } | ||
85 | + } | ||
86 | + bool isMatch = | ||
87 | + (routeSplit.part == pathPart || routeSplit.isParameter()); | ||
88 | + if (isMatch) { | ||
89 | + ParseRouteSplitMatch parentMatch = | ||
90 | + routeSplitMatches[routeSplit.parent]; | ||
91 | + ParseRouteSplitMatch match = | ||
92 | + ParseRouteSplitMatch.fromMatch(parentMatch, routeSplit); | ||
93 | + if (routeSplit.isParameter()) { | ||
94 | + String paramKey = routeSplit.part.substring(1); | ||
95 | + match.parameters[paramKey] = pathPart; | ||
96 | + } | ||
97 | + if (queryMap != null) { | ||
98 | + match.parameters.addAll(queryMap); | ||
99 | + } | ||
100 | + | ||
101 | + currentMatches[routeSplit] = match; | ||
102 | + if (routeSplit.routeSplits != null) { | ||
103 | + nextrouteSplits.addAll(routeSplit.routeSplits); | ||
104 | + } | ||
105 | + } | ||
106 | + } | ||
107 | + routeSplitMatches = currentMatches; | ||
108 | + routeSplitsToCheck = nextrouteSplits; | ||
109 | + if (currentMatches.values.length == 0) { | ||
110 | + return null; | ||
111 | + } | ||
112 | + } | ||
113 | + List<ParseRouteSplitMatch> matches = routeSplitMatches.values.toList(); | ||
114 | + if (matches.length > 0) { | ||
115 | + ParseRouteSplitMatch match = matches.first; | ||
116 | + ParseRouteSplit routeSplitToUse = match.routeSplit; | ||
117 | + | ||
118 | + if (routeSplitToUse != null && | ||
119 | + routeSplitToUse.routes != null && | ||
120 | + routeSplitToUse.routes.length > 0) { | ||
121 | + AppRouteMatch routeMatch = AppRouteMatch(); | ||
122 | + routeMatch.parameters = match.parameters; | ||
123 | + if (routeSplitToUse.isParameter()) { | ||
124 | + routeMatch.route = match.routeSplit.parent.part; | ||
125 | + } else { | ||
126 | + routeMatch.route = match.routeSplit.part; | ||
127 | + } | ||
128 | + return routeMatch; | ||
129 | + } | ||
130 | + } | ||
131 | + return null; | ||
132 | + } | ||
133 | + | ||
134 | + ParseRouteSplit _routeSplitForComponent( | ||
135 | + String component, ParseRouteSplit parent) { | ||
136 | + List<ParseRouteSplit> routeSplits = _routeSplits; | ||
137 | + if (parent != null) { | ||
138 | + routeSplits = parent.routeSplits; | ||
139 | + } | ||
140 | + for (ParseRouteSplit routeSplit in routeSplits) { | ||
141 | + if (routeSplit.part == component) { | ||
142 | + return routeSplit; | ||
143 | + } | ||
144 | + } | ||
145 | + return null; | ||
146 | + } | ||
147 | + | ||
148 | + ParseRouteSplitType _typeForComponent(String component) { | ||
149 | + ParseRouteSplitType type = ParseRouteSplitType.component; | ||
150 | + if (_isParameterComponent(component)) { | ||
151 | + type = ParseRouteSplitType.parameter; | ||
152 | + } | ||
153 | + return type; | ||
154 | + } | ||
155 | + | ||
156 | + bool _isParameterComponent(String component) { | ||
157 | + return component.startsWith(":"); | ||
158 | + } | ||
159 | +} | ||
160 | + | ||
161 | +enum ParseRouteSplitType { | ||
162 | + component, | ||
163 | + parameter, | ||
164 | +} | ||
165 | + | ||
166 | +class AppRouteMatch { | ||
167 | + Map<String, String> parameters = <String, String>{}; | ||
168 | + String route = '/'; | ||
169 | +} | ||
170 | + | ||
171 | +class ParseRouteSplitMatch { | ||
172 | + ParseRouteSplitMatch(this.routeSplit); | ||
173 | + | ||
174 | + ParseRouteSplitMatch.fromMatch(ParseRouteSplitMatch match, this.routeSplit) { | ||
175 | + parameters = <String, String>{}; | ||
176 | + if (match != null) { | ||
177 | + parameters.addAll(match.parameters); | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + ParseRouteSplit routeSplit; | ||
182 | + Map<String, String> parameters = <String, String>{}; | ||
183 | +} | ||
184 | + | ||
185 | +class ParseRouteSplit { | ||
186 | + ParseRouteSplit(this.part, this.type); | ||
187 | + | ||
188 | + String part; | ||
189 | + ParseRouteSplitType type; | ||
190 | + List<String> routes = []; | ||
191 | + List<ParseRouteSplit> routeSplits = <ParseRouteSplit>[]; | ||
192 | + ParseRouteSplit parent; | ||
193 | + | ||
194 | + bool isParameter() { | ||
195 | + return type == ParseRouteSplitType.parameter; | ||
196 | + } | ||
197 | +} |
lib/src/state/get_state.dart
0 → 100644
1 | +import 'package:flutter/material.dart'; | ||
2 | +import '../get_main.dart'; | ||
3 | + | ||
4 | +class GetController extends State { | ||
5 | + Map<GetController, State> _allStates = {}; | ||
6 | + | ||
7 | + /// Update GetBuilder with update(this) | ||
8 | + void update(GetController id) { | ||
9 | + if (id != null) { | ||
10 | + final State state = _allStates[id]; | ||
11 | + if (state != null && state.mounted) state.setState(() {}); | ||
12 | + } | ||
13 | + } | ||
14 | + | ||
15 | + @override | ||
16 | + Widget build(_) => throw ("build method can't be called"); | ||
17 | +} | ||
18 | + | ||
19 | +class GetBuilder<T extends GetController> extends StatefulWidget { | ||
20 | + @required | ||
21 | + final Widget Function(T) builder; | ||
22 | + final bool global; | ||
23 | + final bool autoRemove; | ||
24 | + final void Function(State state) initState, dispose, didChangeDependencies; | ||
25 | + final void Function(GetBuilder oldWidget, State state) didUpdateWidget; | ||
26 | + final T controller; | ||
27 | + GetBuilder({ | ||
28 | + Key key, | ||
29 | + this.controller, | ||
30 | + this.global = true, | ||
31 | + this.builder, | ||
32 | + this.autoRemove = true, | ||
33 | + this.initState, | ||
34 | + this.dispose, | ||
35 | + this.didChangeDependencies, | ||
36 | + this.didUpdateWidget, | ||
37 | + }) : assert(builder != null, controller != null), | ||
38 | + super(key: key); | ||
39 | + @override | ||
40 | + _GetBuilderState<T> createState() => _GetBuilderState<T>(); | ||
41 | +} | ||
42 | + | ||
43 | +class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { | ||
44 | + T controller; | ||
45 | + @override | ||
46 | + void initState() { | ||
47 | + super.initState(); | ||
48 | + if (widget.global) { | ||
49 | + if (Get.isRegistred<T>()) { | ||
50 | + controller = Get.find<T>(); | ||
51 | + } else { | ||
52 | + controller = widget.controller; | ||
53 | + controller._allStates[controller] = this; | ||
54 | + Get.put(controller); | ||
55 | + } | ||
56 | + } else { | ||
57 | + controller = widget.controller; | ||
58 | + controller._allStates[controller] = this; | ||
59 | + } | ||
60 | + if (widget.initState != null) widget.initState(this); | ||
61 | + } | ||
62 | + | ||
63 | + @override | ||
64 | + void dispose() { | ||
65 | + if (controller != null) { | ||
66 | + var b = controller; | ||
67 | + if (b._allStates[controller].hashCode == this.hashCode) { | ||
68 | + b._allStates.remove(controller); | ||
69 | + } | ||
70 | + } | ||
71 | + if (widget.dispose != null) widget.dispose(this); | ||
72 | + if (widget.autoRemove && Get.isRegistred<T>()) { | ||
73 | + Get.delete(controller); | ||
74 | + } | ||
75 | + super.dispose(); | ||
76 | + } | ||
77 | + | ||
78 | + @override | ||
79 | + void didChangeDependencies() { | ||
80 | + super.didChangeDependencies(); | ||
81 | + if (widget.didChangeDependencies != null) | ||
82 | + widget.didChangeDependencies(this); | ||
83 | + } | ||
84 | + | ||
85 | + @override | ||
86 | + void didUpdateWidget(GetBuilder oldWidget) { | ||
87 | + super.didUpdateWidget(oldWidget); | ||
88 | + if (widget.didUpdateWidget != null) widget.didUpdateWidget(oldWidget, this); | ||
89 | + } | ||
90 | + | ||
91 | + @override | ||
92 | + Widget build(BuildContext context) { | ||
93 | + return widget.builder(controller); | ||
94 | + } | ||
95 | +} |
1 | # Generated by pub | 1 | # Generated by pub |
2 | # See https://dart.dev/tools/pub/glossary#lockfile | 2 | # See https://dart.dev/tools/pub/glossary#lockfile |
3 | packages: | 3 | packages: |
4 | + archive: | ||
5 | + dependency: transitive | ||
6 | + description: | ||
7 | + name: archive | ||
8 | + url: "https://pub.dartlang.org" | ||
9 | + source: hosted | ||
10 | + version: "2.0.13" | ||
11 | + args: | ||
12 | + dependency: transitive | ||
13 | + description: | ||
14 | + name: args | ||
15 | + url: "https://pub.dartlang.org" | ||
16 | + source: hosted | ||
17 | + version: "1.6.0" | ||
4 | async: | 18 | async: |
5 | dependency: transitive | 19 | dependency: transitive |
6 | description: | 20 | description: |
@@ -29,6 +43,20 @@ packages: | @@ -29,6 +43,20 @@ packages: | ||
29 | url: "https://pub.dartlang.org" | 43 | url: "https://pub.dartlang.org" |
30 | source: hosted | 44 | source: hosted |
31 | version: "1.14.12" | 45 | version: "1.14.12" |
46 | + convert: | ||
47 | + dependency: transitive | ||
48 | + description: | ||
49 | + name: convert | ||
50 | + url: "https://pub.dartlang.org" | ||
51 | + source: hosted | ||
52 | + version: "2.1.1" | ||
53 | + crypto: | ||
54 | + dependency: transitive | ||
55 | + description: | ||
56 | + name: crypto | ||
57 | + url: "https://pub.dartlang.org" | ||
58 | + source: hosted | ||
59 | + version: "2.1.4" | ||
32 | flutter: | 60 | flutter: |
33 | dependency: "direct main" | 61 | dependency: "direct main" |
34 | description: flutter | 62 | description: flutter |
@@ -39,6 +67,13 @@ packages: | @@ -39,6 +67,13 @@ packages: | ||
39 | description: flutter | 67 | description: flutter |
40 | source: sdk | 68 | source: sdk |
41 | version: "0.0.0" | 69 | version: "0.0.0" |
70 | + image: | ||
71 | + dependency: transitive | ||
72 | + description: | ||
73 | + name: image | ||
74 | + url: "https://pub.dartlang.org" | ||
75 | + source: hosted | ||
76 | + version: "2.1.12" | ||
42 | matcher: | 77 | matcher: |
43 | dependency: transitive | 78 | dependency: transitive |
44 | description: | 79 | description: |
@@ -60,6 +95,13 @@ packages: | @@ -60,6 +95,13 @@ packages: | ||
60 | url: "https://pub.dartlang.org" | 95 | url: "https://pub.dartlang.org" |
61 | source: hosted | 96 | source: hosted |
62 | version: "1.6.4" | 97 | version: "1.6.4" |
98 | + petitparser: | ||
99 | + dependency: transitive | ||
100 | + description: | ||
101 | + name: petitparser | ||
102 | + url: "https://pub.dartlang.org" | ||
103 | + source: hosted | ||
104 | + version: "2.4.0" | ||
63 | quiver: | 105 | quiver: |
64 | dependency: transitive | 106 | dependency: transitive |
65 | description: | 107 | description: |
@@ -128,5 +170,12 @@ packages: | @@ -128,5 +170,12 @@ packages: | ||
128 | url: "https://pub.dartlang.org" | 170 | url: "https://pub.dartlang.org" |
129 | source: hosted | 171 | source: hosted |
130 | version: "2.0.8" | 172 | version: "2.0.8" |
173 | + xml: | ||
174 | + dependency: transitive | ||
175 | + description: | ||
176 | + name: xml | ||
177 | + url: "https://pub.dartlang.org" | ||
178 | + source: hosted | ||
179 | + version: "3.6.1" | ||
131 | sdks: | 180 | sdks: |
132 | dart: ">=2.6.0 <3.0.0" | 181 | dart: ">=2.6.0 <3.0.0" |
1 | name: get | 1 | name: get |
2 | description: Navigate between screens, display snackbars, dialogs and bottomSheets, from anywhere in your code without context with Get. | 2 | description: Navigate between screens, display snackbars, dialogs and bottomSheets, from anywhere in your code without context with Get. |
3 | -version: 1.20.0-dev | 3 | +version: 2.0.0-dev |
4 | homepage: https://github.com/jonataslaw/get | 4 | homepage: https://github.com/jonataslaw/get |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment