Jonny Borges
Committed by GitHub

New Release - Get 2.5

  1 +## [2.5.0]
  2 +- Added List.obs
  3 +- Now you can transform any class on obs
  4 +
  5 +## [2.4.0]
  6 +- Added GetX, state manager rxDart based.
  7 +- Fix error on add for non global controllers
  8 +
  9 +## [2.3.2]
  10 +- Fix close method called on not root GetBuilder
  11 +
  12 +## [2.3.1]
  13 +- Auto close stream inside close method
  14 +- Added docs
  15 +
  16 +## [2.3.0]
  17 +- Added interface to GetX support
  18 +
  19 +## [2.2.8]
  20 +- Added api to platform brightness
  21 +
  22 +## [2.2.7]
  23 +- Fix typos
  24 +
1 ## [2.2.6] 25 ## [2.2.6]
2 - Fix cancel button on defaultDialog don't appear when widget implementation usage 26 - Fix cancel button on defaultDialog don't appear when widget implementation usage
3 27
@@ -183,7 +183,7 @@ With Get, all you have to do is call your Get.snackbar from anywhere in your cod @@ -183,7 +183,7 @@ With Get, all you have to do is call your Get.snackbar from anywhere in your cod
183 /////////////////////////////////// 183 ///////////////////////////////////
184 ``` 184 ```
185 If you prefer the traditional snackbar, or want to customize it from scratch, including adding just one line (Get.snackbar makes use of a mandatory title and message), you can use 185 If you prefer the traditional snackbar, or want to customize it from scratch, including adding just one line (Get.snackbar makes use of a mandatory title and message), you can use
186 -`GetBar().show();` which provides the RAW API on which Get.snackbar was built. 186 +`Get.rawSnackbar();` which provides the RAW API on which Get.snackbar was built.
187 187
188 ### Dialogs 188 ### Dialogs
189 189
@@ -244,7 +244,7 @@ What performance improvements does Get bring? @@ -244,7 +244,7 @@ What performance improvements does Get bring?
244 244
245 2- Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb). 245 2- Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb).
246 246
247 -3- Forget StatefulWidget! With Get you will never need it again. With the other state managers, you will probably have to use a StatefulWidget to get the instance of your Provider, BLoC, MobX Controller, etc. But have you ever stopped to think that your appBar, your scaffold, and most of the widgets that are in your class are stateless? So why save the state of an entire class, if you can only save the state of the Widget that is stateful? Get solves that, too. Create a Stateless class, make everything stateless. If you need to update a single component, wrap it with GetBuilder, and its state will be maintained. 247 +3- Forget StatefulWidget! With Get you will never need it again (if you need to use it, you are using Get incorrectly). With the other state managers, you will probably have to use a StatefulWidget to get the instance of your Provider, BLoC, MobX Controller, etc. But have you ever stopped to think that your appBar, your scaffold, and most of the widgets that are in your class are stateless? So why save the state of an entire class, if you can only save the state of the Widget that is stateful? Get solves that, too. Create a Stateless class, make everything stateless. If you need to update a single component, wrap it with GetBuilder, and its state will be maintained.
248 248
249 4- Organize your project for real! Controllers must not be in your UI, place your TextEditController, or any controller you use within your Controller class. 249 4- Organize your project for real! Controllers must not be in your UI, place your TextEditController, or any controller you use within your Controller class.
250 250
@@ -261,7 +261,7 @@ What performance improvements does Get bring? @@ -261,7 +261,7 @@ What performance improvements does Get bring?
261 261
262 In class A the controller is not yet in memory, because you have not used it yet (Get is lazyLoad). In class B you used the controller, and it entered memory. In class C you used the same controller as in class B, Get will share the state of controller B with controller C, and the same controller is still in memory. If you close screen C and screen B, Get will automatically take controller X out of memory and free up resources, because Class a is not using the controller. If you navigate to B again, controller X will enter memory again, if instead of going to class C, you return to class A again, Get will take the controller out of memory in the same way. If class C didn't use the controller, and you took class B out of memory, no class would be using controller X and likewise it would be disposed of. The only exception that can mess with Get, is if you remove B from the route unexpectedly, and try to use the controller in C. In this case, the creator ID of the controller that was in B was deleted, and Get was programmed to remove it from memory every controller that has no creator ID. If you intend to do this, add the "autoRemove: false" flag to class B's GetBuilder and use adoptID = true; in class C's GetBuilder. 262 In class A the controller is not yet in memory, because you have not used it yet (Get is lazyLoad). In class B you used the controller, and it entered memory. In class C you used the same controller as in class B, Get will share the state of controller B with controller C, and the same controller is still in memory. If you close screen C and screen B, Get will automatically take controller X out of memory and free up resources, because Class a is not using the controller. If you navigate to B again, controller X will enter memory again, if instead of going to class C, you return to class A again, Get will take the controller out of memory in the same way. If class C didn't use the controller, and you took class B out of memory, no class would be using controller X and likewise it would be disposed of. The only exception that can mess with Get, is if you remove B from the route unexpectedly, and try to use the controller in C. In this case, the creator ID of the controller that was in B was deleted, and Get was programmed to remove it from memory every controller that has no creator ID. If you intend to do this, add the "autoRemove: false" flag to class B's GetBuilder and use adoptID = true; in class C's GetBuilder.
263 263
264 -### State manager usage 264 +### Simple state manager usage
265 265
266 ```dart 266 ```dart
267 // Create controller class and extends GetController 267 // Create controller class and extends GetController
@@ -283,8 +283,6 @@ GetBuilder<Controller>( @@ -283,8 +283,6 @@ GetBuilder<Controller>(
283 **Done!** 283 **Done!**
284 - You have already learned how to manage states with Get. 284 - You have already learned how to manage states with Get.
285 285
286 -### Global State manager  
287 -  
288 If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init): 286 If you navigate many routes and need data that was in your previously used controller, you just need to use GetBuilder Again (with no init):
289 287
290 ```dart 288 ```dart
@@ -330,6 +328,39 @@ FloatingActionButton( @@ -330,6 +328,39 @@ FloatingActionButton(
330 ``` 328 ```
331 When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically. 329 When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically.
332 330
  331 +##### No StatefulWidget:
  332 +Using StatefulWidgets means storing the state of entire screens unnecessarily. With Get the use of StatefulWidget is optional. Avoid them and save your users' RAM.
  333 +
  334 +If you need to call initState() or dispose() method, you can call them directly from GetBuilder();
  335 +
  336 +```dart
  337 +GetBuilder<Controller>(
  338 + initState(_) => Controller.to.fetchApi(),
  339 + dispose(_) => Controller.to.closeStreams(),
  340 + builder: (s) => Text('${s.username}'),
  341 + ),
  342 +```
  343 +
  344 +
  345 +- NOTE: If you are working with reactive programming with Get, know that it automatically closes your streams, as long as you close them correctly inside the close() method;
  346 +
  347 +Do not call a dispose method inside GetController, it will not do anything, remember that the controller is not a Widget, you should not "dispose" it, and it will be automatically and intelligently removed from memory by Get. If you used any stream on it and want to close it, just insert it into the close method. Example:
  348 +
  349 +```dart
  350 +class Controller extends GetController {
  351 +StreamController<User> user = StreamController<User>();
  352 +StreamController<String> name = StreamController<String>();
  353 +
  354 +/// close stream = close method, not dispose.
  355 +@override
  356 +void close() {
  357 + user.close();
  358 + name.close();
  359 + super.close();
  360 +}
  361 +
  362 +```
  363 +
333 ##### Forms of use: 364 ##### Forms of use:
334 365
335 - Recommended usage: 366 - Recommended usage:
@@ -384,6 +415,130 @@ GetBuilder( // you dont need to type on this way @@ -384,6 +415,130 @@ GetBuilder( // you dont need to type on this way
384 415
385 ``` 416 ```
386 417
  418 +If you want to refine a widget's update control, you can assign them unique IDs:
  419 +```dart
  420 +GetBuilder<Controller>(
  421 + id: 'text'
  422 + init: Controller(), // use it only first time on each controller
  423 + builder: (_) => Text(
  424 + '${Get.find<Controller>().counter}', //here
  425 + )),
  426 +```
  427 +And update it fis form:
  428 +```dart
  429 +update(this,['text']);
  430 +
  431 +You can also impose conditions for the update:
  432 +
  433 +```
  434 +update(this,['text'], counter < 10);
  435 +
  436 +Why use the update method and why don't we use ChangeNotifier?
  437 +
  438 +
  439 +## Reactive State Manager
  440 +
  441 +If you want power, Get gives you the most advanced state manager you could ever have.
  442 +GetX was built 100% based on Streams, and give you all the firepower that BLoC gave you, with an easier facility than using MobX.
  443 +Without decorations, you can turn anything into Observable with just a ".obs".
  444 +
  445 +Maximum performance: In addition to having a smart algorithm for minimal reconstruction, Get uses comparators to make sure the state has changed. If you experience any errors in your application, and send a duplicate change of state, Get will ensure that your application does not collapse.
  446 +The state only changes if the values ​​change. That's the main difference between Get, and using Computed from MobX. When joining two observables, when one is changed, the hearing of that observable will change. With Get, if you join two variables (which is unnecessary computed for that), GetX (similar to Observer) will only change if it implies a real change of state. Example:
  447 +
  448 +```dart
  449 +final count1 = 0.obs;
  450 +final count2 = 0.obs;
  451 +int get soma => count1.value + count2.value;
  452 +```
  453 +
  454 +```dart
  455 + GetX<Controller>(
  456 + builder: (_) {
  457 + print("count 1 rebuild");
  458 + return Text('${_.count1.value}');
  459 + },
  460 + ),
  461 + GetX<Controller>(
  462 + builder: (_) {
  463 + print("count 2 rebuild");
  464 + return Text('${_.count2.value}');
  465 + },
  466 + ),
  467 + GetX<Controller>(
  468 + builder: (_) {
  469 + print("count 3 rebuild");
  470 + return Text('${_.soma}');
  471 + },
  472 + ),
  473 +```
  474 +
  475 +If we increment the number of count 1, only count 1 and count 3 are reconstructed, because count 1 now has a value of 1, and 1 + 0 = 1, changing the sum value.
  476 +
  477 +If we change count 2, only count2 and 3 are reconstructed, because the value of 2 has changed, and the result of the sum is now 2.
  478 +
  479 +If we add the number 1 to count 1, which already contains 1, no widget is reconstructed. If we add a value of 1 for count 1 and a value of 2 for count 2, only 2 and 3 will be reconstructed, simply because GetX not only changes what is necessary, it avoids duplicating events.
  480 +
  481 +In addition, Get provides refined state control. You can condition an event (such as adding an object to a list), on a certain condition.
  482 +
  483 +```dart
  484 +list.addIf(item<limit, item);
  485 +```
  486 +
  487 +Without decorations, without a code generator, without complications, GetX will change the way you manage your states in Flutter, and that is not a promise, it is a certainty!
  488 +
  489 +Do you know Flutter's counter app? Your Controller class might look like this:
  490 +
  491 +```dart
  492 +class CountCtl extends RxController {
  493 + int count = 0.obs;
  494 +}
  495 +```
  496 +With a simple:
  497 +```dart
  498 +ctl.count.value++
  499 +```
  500 +
  501 +You could update the counter variable in your UI, regardless of where it is stored.
  502 +
  503 +You can transform anything on obs:
  504 +
  505 +```dart
  506 +class RxUser {
  507 + final name = "Camila".obs;
  508 + final age = 18.obs;
  509 +}
  510 +
  511 +class User {
  512 + User({String name, int age});
  513 + final rx = RxUser();
  514 +
  515 + String get name => rx.name.value;
  516 + set name(String value) => rx.name.value = value;
  517 +
  518 + int get age => rx.age.value;
  519 + set age(int value) => rx.age.value = value;
  520 +}
  521 +```
  522 +
  523 +```dart
  524 +
  525 +void main() {
  526 + final user = User();
  527 + print(user.name);
  528 + user.age = 23;
  529 + user.rx.age.listen((int age) => print(age));
  530 + user.age = 24;
  531 + user.age = 25;
  532 +}
  533 +___________
  534 +out:
  535 +Camila
  536 +23
  537 +24
  538 +25
  539 +
  540 +
  541 +
387 ## Simple Instance Manager 542 ## Simple Instance Manager
388 Are you already using Get and want to make your project as lean as possible? Get has a simple and powerful dependency manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code, no Provider context, no inheritedWidget: 543 Are you already using Get and want to make your project as lean as possible? Get has a simple and powerful dependency manager that allows you to retrieve the same class as your Bloc or Controller with just 1 lines of code, no Provider context, no inheritedWidget:
389 544
@@ -409,6 +564,12 @@ And then you will be able to recover your controller data that was obtained back @@ -409,6 +564,12 @@ And then you will be able to recover your controller data that was obtained back
409 Text(controller.textFromApi); 564 Text(controller.textFromApi);
410 ``` 565 ```
411 566
  567 +Looking for lazy loading? You can declare all your controllers, and it will be called only when someone needs it. You can do this with:
  568 +```dart
  569 +Get.lazyPut<Service>(()=> ApiMock());
  570 +/// ApiMock will only be called when someone uses Get.find<Service> for the first time
  571 +```
  572 +
412 To remove a instance of Get: 573 To remove a instance of Get:
413 ```dart 574 ```dart
414 Get.delete<Controller>(); 575 Get.delete<Controller>();
@@ -718,7 +879,7 @@ See how simple it is: @@ -718,7 +879,7 @@ See how simple it is:
718 child: FlatButton( 879 child: FlatButton(
719 color: Colors.blue, 880 color: Colors.blue,
720 onPressed: () { 881 onPressed: () {
721 - Get.toNamed('/second', 1); // navigate by your nested route by index 882 + Get.toNamed('/second', id:1); // navigate by your nested route by index
722 }, 883 },
723 child: Text("Go to second")), 884 child: Text("Go to second")),
724 ), 885 ),
@@ -6,6 +6,10 @@ export 'src/snackbar/snack.dart'; @@ -6,6 +6,10 @@ 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'; 8 export 'src/state/get_state.dart';
  9 +export 'src/rx/rx_interface.dart';
  10 +export 'src/rx/rx_impl.dart';
  11 +export 'src/rx/rx_getbuilder.dart';
  12 +export 'src/rx/rx_listview_builder.dart';
9 export 'src/root/root_widget.dart'; 13 export 'src/root/root_widget.dart';
10 export 'src/routes/default_route.dart'; 14 export 'src/routes/default_route.dart';
11 export 'src/routes/get_route.dart'; 15 export 'src/routes/get_route.dart';
@@ -6,24 +6,10 @@ import 'root/root_controller.dart'; @@ -6,24 +6,10 @@ import 'root/root_controller.dart';
6 import 'routes/default_route.dart'; 6 import 'routes/default_route.dart';
7 import 'routes/observers/route_observer.dart'; 7 import 'routes/observers/route_observer.dart';
8 import 'routes/transitions_type.dart'; 8 import 'routes/transitions_type.dart';
  9 +import 'rx/rx_interface.dart';
9 import 'snackbar/snack.dart'; 10 import 'snackbar/snack.dart';
10 11
11 class Get { 12 class Get {
12 - static Get _get;  
13 - static GlobalKey<NavigatorState> _key;  
14 -  
15 - static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) {  
16 - _key = newKey;  
17 - return _key;  
18 - }  
19 -  
20 - static GlobalKey<NavigatorState> get key {  
21 - if (_key == null) {  
22 - _key = GlobalKey<NavigatorState>();  
23 - }  
24 - return _key;  
25 - }  
26 -  
27 ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, 13 ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
28 ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" 14 ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
29 ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. 15 ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
@@ -35,6 +21,15 @@ class Get { @@ -35,6 +21,15 @@ class Get {
35 return _get; 21 return _get;
36 } 22 }
37 23
  24 + bool _enableLog = true;
  25 + bool _defaultPopGesture = GetPlatform.isIOS;
  26 + bool _defaultOpaqueRoute = true;
  27 + Transition _defaultTransition =
  28 + (GetPlatform.isIOS ? Transition.cupertino : Transition.fade);
  29 + Duration _defaultDurationTransition = Duration(milliseconds: 400);
  30 + bool _defaultGlobalState = true;
  31 + RouteSettings _settings;
  32 +
38 ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement, 33 ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
39 ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named" 34 ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
40 ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed. 35 ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
@@ -43,14 +38,21 @@ class Get { @@ -43,14 +38,21 @@ class Get {
43 ///the parentheses and the magic will occur. 38 ///the parentheses and the magic will occur.
44 Get._(); 39 Get._();
45 40
46 - static bool _enableLog = true;  
47 - static bool _defaultPopGesture = GetPlatform.isIOS;  
48 - static bool _defaultOpaqueRoute = true;  
49 - static Transition _defaultTransition =  
50 - (GetPlatform.isIOS ? Transition.cupertino : Transition.fade);  
51 - static Duration _defaultDurationTransition = Duration(milliseconds: 400);  
52 - static bool _defaultGlobalState = true;  
53 - static RouteSettings _settings; 41 + static Get _get;
  42 +
  43 + GlobalKey<NavigatorState> _key;
  44 +
  45 + static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) {
  46 + _get._key = newKey;
  47 + return _get._key;
  48 + }
  49 +
  50 + static GlobalKey<NavigatorState> get key {
  51 + if (_get._key == null) {
  52 + _get._key = GlobalKey<NavigatorState>();
  53 + }
  54 + return _get._key;
  55 + }
54 56
55 /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push 57 /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push
56 /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior 58 /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
@@ -60,13 +62,18 @@ class Get { @@ -60,13 +62,18 @@ class Get {
60 Transition transition, 62 Transition transition,
61 Duration duration, 63 Duration duration,
62 int id, 64 int id,
  65 + bool fullscreenDialog = false,
  66 + Object arguments,
63 bool popGesture}) { 67 bool popGesture}) {
64 - return global(id).currentState.push(GetRouteBase( 68 + return _get.global(id).currentState.push(GetRouteBase(
65 opaque: opaque ?? true, 69 opaque: opaque ?? true,
66 page: page, 70 page: page,
67 - popGesture: popGesture ?? _defaultPopGesture,  
68 - transition: transition ?? _defaultTransition,  
69 - transitionDuration: duration ?? _defaultDurationTransition)); 71 + settings: RouteSettings(
  72 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  73 + popGesture: popGesture ?? _get._defaultPopGesture,
  74 + transition: transition ?? _get._defaultTransition,
  75 + fullscreenDialog: fullscreenDialog,
  76 + transitionDuration: duration ?? _get._defaultDurationTransition));
70 } 77 }
71 78
72 /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed 79 /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed
@@ -75,14 +82,15 @@ class Get { @@ -75,14 +82,15 @@ class Get {
75 static Future<T> toNamed<T>(String page, {arguments, int id}) { 82 static Future<T> toNamed<T>(String page, {arguments, int id}) {
76 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 83 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
77 // when widget don't mounted 84 // when widget don't mounted
78 - return global(id).currentState.pushNamed(page, arguments: arguments); 85 + return _get.global(id).currentState.pushNamed(page, arguments: arguments);
79 } 86 }
80 87
81 /// It replaces Navigator.pushReplacementNamed, but needs no context. 88 /// It replaces Navigator.pushReplacementNamed, but needs no context.
82 static Future<T> offNamed<T>(String page, {arguments, int id}) { 89 static Future<T> offNamed<T>(String page, {arguments, int id}) {
83 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 90 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
84 // when widget don't mounted 91 // when widget don't mounted
85 - return global(id) 92 + return _get
  93 + .global(id)
86 .currentState 94 .currentState
87 .pushReplacementNamed(page, arguments: arguments); 95 .pushReplacementNamed(page, arguments: arguments);
88 } 96 }
@@ -91,24 +99,35 @@ class Get { @@ -91,24 +99,35 @@ class Get {
91 static void until(predicate, {int id}) { 99 static void until(predicate, {int id}) {
92 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 100 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
93 // when widget don't mounted 101 // when widget don't mounted
94 - return global(id).currentState.popUntil(predicate); 102 + return _get.global(id).currentState.popUntil(predicate);
95 } 103 }
96 104
97 /// It replaces Navigator.pushAndRemoveUntil, but needs no context. 105 /// It replaces Navigator.pushAndRemoveUntil, but needs no context.
98 static Future<T> offUntil<T>(page, predicate, {int id}) { 106 static Future<T> offUntil<T>(page, predicate, {int id}) {
99 // if (key.currentState.mounted) // add this if appear problems on future with route navigate 107 // if (key.currentState.mounted) // add this if appear problems on future with route navigate
100 // when widget don't mounted 108 // when widget don't mounted
101 - return global(id).currentState.pushAndRemoveUntil(page, predicate); 109 + return _get.global(id).currentState.pushAndRemoveUntil(page, predicate);
102 } 110 }
103 111
104 /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. 112 /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
105 static Future<T> offNamedUntil<T>(page, predicate, {int id}) { 113 static Future<T> offNamedUntil<T>(page, predicate, {int id}) {
106 - return global(id).currentState.pushNamedAndRemoveUntil(page, predicate); 114 + return _get
  115 + .global(id)
  116 + .currentState
  117 + .pushNamedAndRemoveUntil(page, predicate);
  118 + }
  119 +
  120 + /// It replaces Navigator.popAndPushNamed, but needs no context.
  121 + static Future<T> offAndToNamed<T>(String page, {arguments, int id, result}) {
  122 + return _get
  123 + .global(id)
  124 + .currentState
  125 + .popAndPushNamed(page, arguments: arguments, result: result);
107 } 126 }
108 127
109 /// It replaces Navigator.removeRoute, but needs no context. 128 /// It replaces Navigator.removeRoute, but needs no context.
110 static void removeRoute(route, {int id}) { 129 static void removeRoute(route, {int id}) {
111 - return global(id).currentState.removeRoute(route); 130 + return _get.global(id).currentState.removeRoute(route);
112 } 131 }
113 132
114 /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context. 133 /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
@@ -116,7 +135,7 @@ class Get { @@ -116,7 +135,7 @@ class Get {
116 {RoutePredicate predicate, arguments, int id}) { 135 {RoutePredicate predicate, arguments, int id}) {
117 var route = (Route<dynamic> rota) => false; 136 var route = (Route<dynamic> rota) => false;
118 137
119 - return global(id).currentState.pushNamedAndRemoveUntil( 138 + return _get.global(id).currentState.pushNamedAndRemoveUntil(
120 newRouteName, predicate ?? route, 139 newRouteName, predicate ?? route,
121 arguments: arguments); 140 arguments: arguments);
122 } 141 }
@@ -134,7 +153,7 @@ class Get { @@ -134,7 +153,7 @@ class Get {
134 return (isOverlaysClosed); 153 return (isOverlaysClosed);
135 }); 154 });
136 } 155 }
137 - global(id).currentState.pop(result); 156 + _get.global(id).currentState.pop(result);
138 } 157 }
139 158
140 // /// Experimental API to back from overlay 159 // /// Experimental API to back from overlay
@@ -148,7 +167,7 @@ class Get { @@ -148,7 +167,7 @@ class Get {
148 times = 1; 167 times = 1;
149 } 168 }
150 int count = 0; 169 int count = 0;
151 - void back = global(id).currentState.popUntil((route) { 170 + void back = _get.global(id).currentState.popUntil((route) {
152 return count++ == times; 171 return count++ == times;
153 }); 172 });
154 return back; 173 return back;
@@ -162,13 +181,18 @@ class Get { @@ -162,13 +181,18 @@ class Get {
162 Transition transition, 181 Transition transition,
163 bool popGesture, 182 bool popGesture,
164 int id, 183 int id,
  184 + Object arguments,
  185 + bool fullscreenDialog = false,
165 Duration duration}) { 186 Duration duration}) {
166 - return global(id).currentState.pushReplacement(GetRouteBase( 187 + return _get.global(id).currentState.pushReplacement(GetRouteBase(
167 opaque: opaque ?? true, 188 opaque: opaque ?? true,
168 page: page, 189 page: page,
169 - popGesture: popGesture ?? _defaultPopGesture,  
170 - transition: transition ?? _defaultTransition,  
171 - transitionDuration: duration ?? _defaultDurationTransition)); 190 + settings: RouteSettings(
  191 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  192 + fullscreenDialog: fullscreenDialog,
  193 + popGesture: popGesture ?? _get._defaultPopGesture,
  194 + transition: transition ?? _get._defaultTransition,
  195 + transitionDuration: duration ?? _get._defaultDurationTransition));
172 } 196 }
173 197
174 /// It replaces Navigator.pushAndRemoveUntil, but needs no context 198 /// It replaces Navigator.pushAndRemoveUntil, but needs no context
@@ -177,15 +201,20 @@ class Get { @@ -177,15 +201,20 @@ class Get {
177 bool opaque = false, 201 bool opaque = false,
178 bool popGesture, 202 bool popGesture,
179 int id, 203 int id,
  204 + Object arguments,
  205 + bool fullscreenDialog = false,
180 Transition transition}) { 206 Transition transition}) {
181 var route = (Route<dynamic> rota) => false; 207 var route = (Route<dynamic> rota) => false;
182 208
183 - return global(id).currentState.pushAndRemoveUntil( 209 + return _get.global(id).currentState.pushAndRemoveUntil(
184 GetRouteBase( 210 GetRouteBase(
185 opaque: opaque ?? true, 211 opaque: opaque ?? true,
186 - popGesture: popGesture ?? _defaultPopGesture, 212 + popGesture: popGesture ?? _get._defaultPopGesture,
187 page: page, 213 page: page,
188 - transition: transition ?? _defaultTransition, 214 + settings: RouteSettings(
  215 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  216 + fullscreenDialog: fullscreenDialog,
  217 + transition: transition ?? _get._defaultTransition,
189 ), 218 ),
190 predicate ?? route); 219 predicate ?? route);
191 } 220 }
@@ -537,7 +566,7 @@ class Get { @@ -537,7 +566,7 @@ class Get {
537 } 566 }
538 567
539 /// change default config of Get 568 /// change default config of Get
540 - static void config( 569 + Get.config(
541 {bool enableLog, 570 {bool enableLog,
542 bool defaultPopGesture, 571 bool defaultPopGesture,
543 bool defaultOpaqueRoute, 572 bool defaultOpaqueRoute,
@@ -545,45 +574,47 @@ class Get { @@ -545,45 +574,47 @@ class Get {
545 bool defaultGlobalState, 574 bool defaultGlobalState,
546 Transition defaultTransition}) { 575 Transition defaultTransition}) {
547 if (enableLog != null) { 576 if (enableLog != null) {
548 - _enableLog = enableLog; 577 + _get._enableLog = enableLog;
549 } 578 }
550 if (defaultPopGesture != null) { 579 if (defaultPopGesture != null) {
551 - _defaultPopGesture = defaultPopGesture; 580 + _get._defaultPopGesture = defaultPopGesture;
552 } 581 }
553 if (defaultOpaqueRoute != null) { 582 if (defaultOpaqueRoute != null) {
554 - _defaultOpaqueRoute = defaultOpaqueRoute; 583 + _get._defaultOpaqueRoute = defaultOpaqueRoute;
555 } 584 }
556 if (defaultTransition != null) { 585 if (defaultTransition != null) {
557 - _defaultTransition = defaultTransition; 586 + _get._defaultTransition = defaultTransition;
558 } 587 }
559 588
560 if (defaultDurationTransition != null) { 589 if (defaultDurationTransition != null) {
561 - _defaultDurationTransition = defaultDurationTransition; 590 + _get._defaultDurationTransition = defaultDurationTransition;
562 } 591 }
563 592
564 if (defaultGlobalState != null) { 593 if (defaultGlobalState != null) {
565 - _defaultGlobalState = defaultGlobalState; 594 + _get._defaultGlobalState = defaultGlobalState;
566 } 595 }
567 } 596 }
568 597
569 - static GetMaterialController getController = GetMaterialController(); 598 + GetMaterialController _getController = GetMaterialController();
  599 +
  600 + GetMaterialController get getController => _getController;
570 601
571 - static changeTheme(ThemeData theme) {  
572 - getController.setTheme(theme); 602 + Get.changeTheme(ThemeData theme) {
  603 + _get._getController.setTheme(theme);
573 } 604 }
574 605
575 - static restartApp() {  
576 - getController.restartApp(); 606 + Get.restartApp() {
  607 + _get._getController.restartApp();
577 } 608 }
578 609
579 - static Map<int, GlobalKey<NavigatorState>> _keys = {}; 610 + Map<int, GlobalKey<NavigatorState>> _keys = {};
580 611
581 static GlobalKey<NavigatorState> nestedKey(int key) { 612 static GlobalKey<NavigatorState> nestedKey(int key) {
582 - _keys.putIfAbsent(key, () => GlobalKey<NavigatorState>());  
583 - return _keys[key]; 613 + _get._keys.putIfAbsent(key, () => GlobalKey<NavigatorState>());
  614 + return _get._keys[key];
584 } 615 }
585 616
586 - static GlobalKey<NavigatorState> global(int k) { 617 + GlobalKey<NavigatorState> global(int k) {
587 if (k == null) { 618 if (k == null) {
588 return key; 619 return key;
589 } 620 }
@@ -713,70 +744,78 @@ class Get { @@ -713,70 +744,78 @@ class Get {
713 Get()._singl.containsKey(_getKey(S, name)); 744 Get()._singl.containsKey(_getKey(S, name));
714 745
715 /// give access to Routing API from GetObserver 746 /// give access to Routing API from GetObserver
716 - static Routing get routing => _routing; 747 + static Routing get routing => _get._routing;
717 748
718 - static RouteSettings get routeSettings => _settings; 749 + static RouteSettings get routeSettings => _get._settings;
719 750
720 - static Routing _routing; 751 + Routing _routing;
721 752
722 - static Map<String, String> _parameters = {}; 753 + Map<String, String> _parameters = {};
723 754
724 - static setParameter(Map<String, String> param) {  
725 - _parameters = param; 755 + Get.setParameter(Map<String, String> param) {
  756 + _get._parameters = param;
726 } 757 }
727 758
728 - static setRouting(Routing rt) {  
729 - _routing = rt; 759 + Get.setRouting(Routing rt) {
  760 + _get._routing = rt;
730 } 761 }
731 762
732 - static setSettings(RouteSettings settings) {  
733 - _settings = settings; 763 + Get.setSettings(RouteSettings settings) {
  764 + _get._settings = settings;
734 } 765 }
735 766
736 /// give current arguments 767 /// give current arguments
737 - static get arguments => _routing.args; 768 + static Object get arguments => _get._routing.args;
738 769
739 /// give current arguments 770 /// give current arguments
740 - static Map<String, String> get parameters => _parameters; 771 + static Map<String, String> get parameters => _get._parameters;
  772 +
  773 + /// interface to GetX
  774 + RxInterface _obs;
  775 +
  776 + static RxInterface get obs => _get._obs;
  777 +
  778 + static set obs(RxInterface observer) => _get._obs = observer;
741 779
742 /// give arguments from previous route 780 /// give arguments from previous route
743 - static get previousArguments => _routing.previousArgs; 781 + static get previousArguments => _get._routing.previousArgs;
744 782
745 /// give name from current route 783 /// give name from current route
746 - static get currentRoute => _routing.current; 784 + static get currentRoute => _get._routing.current;
747 785
748 /// give name from previous route 786 /// give name from previous route
749 - static get previousRoute => _routing.previous; 787 + static get previousRoute => _get._routing.previous;
750 788
751 /// check if snackbar is open 789 /// check if snackbar is open
752 - static bool get isSnackbarOpen => _routing.isSnackbar; 790 + static bool get isSnackbarOpen => _get._routing.isSnackbar;
753 791
754 /// check if dialog is open 792 /// check if dialog is open
755 - static bool get isDialogOpen => _routing.isDialog; 793 + static bool get isDialogOpen => _get._routing.isDialog;
756 794
757 /// check if bottomsheet is open 795 /// check if bottomsheet is open
758 - static bool get isBottomSheetOpen => _routing.isBottomSheet; 796 + static bool get isBottomSheetOpen => _get._routing.isBottomSheet;
759 797
760 /// check a raw current route 798 /// check a raw current route
761 - static Route<dynamic> get rawRoute => _routing.route; 799 + static Route<dynamic> get rawRoute => _get._routing.route;
762 800
763 /// check if log is enable 801 /// check if log is enable
764 - static bool get isLogEnable => _enableLog; 802 + static bool get isLogEnable => _get._enableLog;
765 803
766 /// default duration of transition animation 804 /// default duration of transition animation
767 /// default duration work only API 2.0 805 /// default duration work only API 2.0
768 - static Duration get defaultDurationTransition => _defaultDurationTransition; 806 + static Duration get defaultDurationTransition =>
  807 + _get._defaultDurationTransition;
769 808
770 /// give global state of all GetState by default 809 /// give global state of all GetState by default
771 - static bool get defaultGlobalState => _defaultGlobalState; 810 + static bool get defaultGlobalState => _get._defaultGlobalState;
772 811
773 /// check if popGesture is enable 812 /// check if popGesture is enable
774 - static bool get isPopGestureEnable => _defaultPopGesture; 813 + static bool get isPopGestureEnable => _get._defaultPopGesture;
775 814
776 /// check if default opaque route is enable 815 /// check if default opaque route is enable
777 - static bool get isOpaqueRouteDefault => _defaultOpaqueRoute; 816 + static bool get isOpaqueRouteDefault => _get._defaultOpaqueRoute;
778 817
779 - static Transition get defaultTransition => _defaultTransition; 818 + static Transition get defaultTransition => _get._defaultTransition;
780 819
781 /// give access to currentContext 820 /// give access to currentContext
782 static BuildContext get context => key.currentContext; 821 static BuildContext get context => key.currentContext;
@@ -793,6 +832,13 @@ class Get { @@ -793,6 +832,13 @@ class Get {
793 /// give access to Mediaquery.of(context) 832 /// give access to Mediaquery.of(context)
794 static MediaQueryData get mediaQuery => MediaQuery.of(context); 833 static MediaQueryData get mediaQuery => MediaQuery.of(context);
795 834
  835 + /// Check if dark mode theme is enable
  836 + static get isDarkMode => (theme.brightness == Brightness.dark);
  837 +
  838 + /// Check if dark mode theme is enable on platform on android Q+
  839 + static get isPlatformDarkMode =>
  840 + (mediaQuery.platformBrightness == Brightness.dark);
  841 +
796 /// give access to Theme.of(context).iconTheme.color 842 /// give access to Theme.of(context).iconTheme.color
797 static Color get iconColor => Theme.of(context).iconTheme.color; 843 static Color get iconColor => Theme.of(context).iconTheme.color;
798 844
  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter/scheduler.dart';
  3 +import 'bottomsheet/bottomsheet.dart';
  4 +import 'platform/platform.dart';
  5 +import 'root/root_controller.dart';
  6 +import 'routes/default_route.dart';
  7 +import 'routes/observers/route_observer.dart';
  8 +import 'routes/transitions_type.dart';
  9 +import 'rx/rx_interface.dart';
  10 +import 'snackbar/snack.dart';
  11 +
  12 +class Get {
  13 + static Get _get;
  14 + static GlobalKey<NavigatorState> _key;
  15 +
  16 + static GlobalKey<NavigatorState> addKey(GlobalKey<NavigatorState> newKey) {
  17 + _key = newKey;
  18 + return _key;
  19 + }
  20 +
  21 + static GlobalKey<NavigatorState> get key {
  22 + if (_key == null) {
  23 + _key = GlobalKey<NavigatorState>();
  24 + }
  25 + return _key;
  26 + }
  27 +
  28 + ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
  29 + ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
  30 + ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
  31 + ///To return to the previous screen, use Get.back().
  32 + ///No need to pass any context to Get, just put the name of the route inside
  33 + ///the parentheses and the magic will occur.
  34 + factory Get() {
  35 + if (_get == null) _get = Get._();
  36 + return _get;
  37 + }
  38 +
  39 + ///Use Get.to instead of Navigator.push, Get.off instead of Navigator.pushReplacement,
  40 + ///Get.offAll instead of Navigator.pushAndRemoveUntil. For named routes just add "named"
  41 + ///after them. Example: Get.toNamed, Get.offNamed, and Get.AllNamed.
  42 + ///To return to the previous screen, use Get.back().
  43 + ///No need to pass any context to Get, just put the name of the route inside
  44 + ///the parentheses and the magic will occur.
  45 + Get._();
  46 +
  47 + static bool _enableLog = true;
  48 + static bool _defaultPopGesture = GetPlatform.isIOS;
  49 + static bool _defaultOpaqueRoute = true;
  50 + static Transition _defaultTransition =
  51 + (GetPlatform.isIOS ? Transition.cupertino : Transition.fade);
  52 + static Duration _defaultDurationTransition = Duration(milliseconds: 400);
  53 + static bool _defaultGlobalState = true;
  54 + static RouteSettings _settings;
  55 +
  56 + /// It replaces Navigator.push, but needs no context, and it doesn't have the Navigator.push
  57 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  58 + /// of rebuilding every app after a route, use opaque = true as the parameter.
  59 + static Future<T> to<T>(Widget page,
  60 + {bool opaque,
  61 + Transition transition,
  62 + Duration duration,
  63 + int id,
  64 + bool fullscreenDialog = false,
  65 + Object arguments,
  66 + bool popGesture}) {
  67 + return global(id).currentState.push(GetRouteBase(
  68 + opaque: opaque ?? true,
  69 + page: page,
  70 + settings: RouteSettings(
  71 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  72 + popGesture: popGesture ?? _defaultPopGesture,
  73 + transition: transition ?? _defaultTransition,
  74 + fullscreenDialog: fullscreenDialog,
  75 + transitionDuration: duration ?? _defaultDurationTransition));
  76 + }
  77 +
  78 + /// It replaces Navigator.pushNamed, but needs no context, and it doesn't have the Navigator.pushNamed
  79 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  80 + /// of rebuilding every app after a route, use opaque = true as the parameter.
  81 + static Future<T> toNamed<T>(String page, {arguments, int id}) {
  82 + // if (key.currentState.mounted) // add this if appear problems on future with route navigate
  83 + // when widget don't mounted
  84 + return global(id).currentState.pushNamed(page, arguments: arguments);
  85 + }
  86 +
  87 + /// It replaces Navigator.pushReplacementNamed, but needs no context.
  88 + static Future<T> offNamed<T>(String page, {arguments, int id}) {
  89 + // if (key.currentState.mounted) // add this if appear problems on future with route navigate
  90 + // when widget don't mounted
  91 + return global(id)
  92 + .currentState
  93 + .pushReplacementNamed(page, arguments: arguments);
  94 + }
  95 +
  96 + /// It replaces Navigator.popUntil, but needs no context.
  97 + static void until(predicate, {int id}) {
  98 + // if (key.currentState.mounted) // add this if appear problems on future with route navigate
  99 + // when widget don't mounted
  100 + return global(id).currentState.popUntil(predicate);
  101 + }
  102 +
  103 + /// It replaces Navigator.pushAndRemoveUntil, but needs no context.
  104 + static Future<T> offUntil<T>(page, predicate, {int id}) {
  105 + // if (key.currentState.mounted) // add this if appear problems on future with route navigate
  106 + // when widget don't mounted
  107 + return global(id).currentState.pushAndRemoveUntil(page, predicate);
  108 + }
  109 +
  110 + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
  111 + static Future<T> offNamedUntil<T>(page, predicate, {int id}) {
  112 + return global(id).currentState.pushNamedAndRemoveUntil(page, predicate);
  113 + }
  114 +
  115 + /// It replaces Navigator.popAndPushNamed, but needs no context.
  116 + static Future<T> offAndToNamed<T>(String page, {arguments, int id, result}) {
  117 + return global(id)
  118 + .currentState
  119 + .popAndPushNamed(page, arguments: arguments, result: result);
  120 + }
  121 +
  122 + /// It replaces Navigator.removeRoute, but needs no context.
  123 + static void removeRoute(route, {int id}) {
  124 + return global(id).currentState.removeRoute(route);
  125 + }
  126 +
  127 + /// It replaces Navigator.pushNamedAndRemoveUntil, but needs no context.
  128 + static Future<T> offAllNamed<T>(String newRouteName,
  129 + {RoutePredicate predicate, arguments, int id}) {
  130 + var route = (Route<dynamic> rota) => false;
  131 +
  132 + return global(id).currentState.pushNamedAndRemoveUntil(
  133 + newRouteName, predicate ?? route,
  134 + arguments: arguments);
  135 + }
  136 +
  137 + static bool get isOverlaysOpen =>
  138 + (isSnackbarOpen || isDialogOpen || isBottomSheetOpen);
  139 +
  140 + static bool get isOverlaysClosed =>
  141 + (!Get.isSnackbarOpen && !Get.isDialogOpen && !Get.isBottomSheetOpen);
  142 +
  143 + /// It replaces Navigator.pop, but needs no context.
  144 + static void back({dynamic result, bool closeOverlays = false, int id}) {
  145 + if (closeOverlays && isOverlaysOpen) {
  146 + navigator.popUntil((route) {
  147 + return (isOverlaysClosed);
  148 + });
  149 + }
  150 + global(id).currentState.pop(result);
  151 + }
  152 +
  153 + // /// Experimental API to back from overlay
  154 + // static void backE({dynamic result}) {
  155 + // Navigator.pop(overlayContext);
  156 + // }
  157 +
  158 + /// It will close as many screens as you define. Times must be> 0;
  159 + static void close(int times, [int id]) {
  160 + if ((times == null) || (times < 1)) {
  161 + times = 1;
  162 + }
  163 + int count = 0;
  164 + void back = global(id).currentState.popUntil((route) {
  165 + return count++ == times;
  166 + });
  167 + return back;
  168 + }
  169 +
  170 + /// It replaces Navigator.pushReplacement, but needs no context, and it doesn't have the Navigator.pushReplacement
  171 + /// routes rebuild bug present in Flutter. If for some strange reason you want the default behavior
  172 + /// of rebuilding every app after a route, use opaque = true as the parameter.
  173 + static Future<T> off<T>(Widget page,
  174 + {bool opaque = false,
  175 + Transition transition,
  176 + bool popGesture,
  177 + int id,
  178 + Object arguments,
  179 + bool fullscreenDialog = false,
  180 + Duration duration}) {
  181 + return global(id).currentState.pushReplacement(GetRouteBase(
  182 + opaque: opaque ?? true,
  183 + page: page,
  184 + settings: RouteSettings(
  185 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  186 + fullscreenDialog: fullscreenDialog,
  187 + popGesture: popGesture ?? _defaultPopGesture,
  188 + transition: transition ?? _defaultTransition,
  189 + transitionDuration: duration ?? _defaultDurationTransition));
  190 + }
  191 +
  192 + /// It replaces Navigator.pushAndRemoveUntil, but needs no context
  193 + static Future<T> offAll<T>(Widget page,
  194 + {RoutePredicate predicate,
  195 + bool opaque = false,
  196 + bool popGesture,
  197 + int id,
  198 + Object arguments,
  199 + bool fullscreenDialog = false,
  200 + Transition transition}) {
  201 + var route = (Route<dynamic> rota) => false;
  202 +
  203 + return global(id).currentState.pushAndRemoveUntil(
  204 + GetRouteBase(
  205 + opaque: opaque ?? true,
  206 + popGesture: popGesture ?? _defaultPopGesture,
  207 + page: page,
  208 + settings: RouteSettings(
  209 + name: '/' + page.toString().toLowerCase(), arguments: arguments),
  210 + fullscreenDialog: fullscreenDialog,
  211 + transition: transition ?? _defaultTransition,
  212 + ),
  213 + predicate ?? route);
  214 + }
  215 +
  216 + /// Show a dialog
  217 + static Future<T> dialog<T>(
  218 + Widget child, {
  219 + bool barrierDismissible = true,
  220 + bool useRootNavigator = true,
  221 + // RouteSettings routeSettings
  222 + }) {
  223 + return showDialog(
  224 + barrierDismissible: barrierDismissible,
  225 + useRootNavigator: useRootNavigator,
  226 + routeSettings: RouteSettings(name: 'dialog'),
  227 + context: overlayContext,
  228 + builder: (_) {
  229 + return child;
  230 + },
  231 + );
  232 + }
  233 +
  234 + /// Api from showGeneralDialog with no context
  235 + static Future<T> generalDialog<T>({
  236 + @required RoutePageBuilder pageBuilder,
  237 + bool barrierDismissible,
  238 + String barrierLabel,
  239 + Color barrierColor,
  240 + Duration transitionDuration,
  241 + RouteTransitionsBuilder transitionBuilder,
  242 + bool useRootNavigator = true,
  243 + RouteSettings routeSettings,
  244 + // RouteSettings routeSettings
  245 + }) {
  246 + return showGeneralDialog(
  247 + pageBuilder: pageBuilder,
  248 + barrierDismissible: barrierDismissible,
  249 + barrierLabel: barrierLabel,
  250 + barrierColor: barrierColor,
  251 + transitionDuration: transitionDuration,
  252 + transitionBuilder: transitionBuilder,
  253 + useRootNavigator: useRootNavigator,
  254 + routeSettings: RouteSettings(name: 'dialog'),
  255 + context: overlayContext,
  256 + );
  257 + }
  258 +
  259 + static Future<T> defaultDialog<T>({
  260 + String title = "Alert",
  261 + Widget content,
  262 + VoidCallback onConfirm,
  263 + VoidCallback onCancel,
  264 + VoidCallback onCustom,
  265 + String textConfirm,
  266 + String textCancel,
  267 + String textCustom,
  268 + Widget confirm,
  269 + Widget cancel,
  270 + Widget custom,
  271 + Color backgroundColor,
  272 + Color buttonColor,
  273 + String middleText = "Dialog made in 3 lines of code",
  274 + double radius = 20.0,
  275 + List<Widget> actions,
  276 + }) {
  277 + bool leanCancel = onCancel != null || textCancel != null;
  278 + bool leanConfirm = onConfirm != null || textConfirm != null;
  279 + actions ??= [];
  280 +
  281 + if (cancel != null) {
  282 + actions.add(cancel);
  283 + } else {
  284 + if (leanCancel) {
  285 + actions.add(FlatButton(
  286 + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  287 + onPressed: () {
  288 + onCancel?.call();
  289 + Get.back();
  290 + },
  291 + padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8),
  292 + child: Text(textCancel ?? "Cancel"),
  293 + shape: RoundedRectangleBorder(
  294 + side: BorderSide(
  295 + color: buttonColor ?? Get.theme.accentColor,
  296 + width: 2,
  297 + style: BorderStyle.solid),
  298 + borderRadius: BorderRadius.circular(100)),
  299 + ));
  300 + }
  301 + }
  302 + if (confirm != null) {
  303 + actions.add(confirm);
  304 + } else {
  305 + if (leanConfirm) {
  306 + actions.add(FlatButton(
  307 + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  308 + color: buttonColor ?? Get.theme.accentColor,
  309 + shape: RoundedRectangleBorder(
  310 + borderRadius: BorderRadius.circular(100)),
  311 + child: Text(textConfirm ?? "Ok"),
  312 + onPressed: () {
  313 + onConfirm?.call();
  314 + }));
  315 + }
  316 + }
  317 + return Get.dialog(AlertDialog(
  318 + titlePadding: EdgeInsets.all(8),
  319 + contentPadding: EdgeInsets.all(8),
  320 + backgroundColor: backgroundColor ?? Get.theme.dialogBackgroundColor,
  321 + shape: RoundedRectangleBorder(
  322 + borderRadius: BorderRadius.all(Radius.circular(radius))),
  323 + title: Text(title, textAlign: TextAlign.center),
  324 + content: Column(
  325 + crossAxisAlignment: CrossAxisAlignment.center,
  326 + mainAxisSize: MainAxisSize.min,
  327 + children: [
  328 + content ?? Text(middleText ?? "", textAlign: TextAlign.center),
  329 + SizedBox(height: 16),
  330 + ButtonTheme(
  331 + minWidth: 78.0,
  332 + height: 34.0,
  333 + child: Wrap(
  334 + alignment: WrapAlignment.center,
  335 + spacing: 8,
  336 + runSpacing: 8,
  337 + children: actions,
  338 + ),
  339 + )
  340 + ],
  341 + ),
  342 + // actions: actions, // ?? <Widget>[cancelButton, confirmButton],
  343 + buttonPadding: EdgeInsets.zero,
  344 + ));
  345 + }
  346 +
  347 + static Future<T> bottomSheet<T>(
  348 + Widget bottomsheet, {
  349 + Color backgroundColor,
  350 + double elevation,
  351 + ShapeBorder shape,
  352 + Clip clipBehavior,
  353 + Color barrierColor,
  354 + bool ignoreSafeArea,
  355 + bool isScrollControlled = false,
  356 + bool useRootNavigator = false,
  357 + bool isDismissible = true,
  358 + bool enableDrag = true,
  359 + }) {
  360 + assert(bottomsheet != null);
  361 + assert(isScrollControlled != null);
  362 + assert(useRootNavigator != null);
  363 + assert(isDismissible != null);
  364 + assert(enableDrag != null);
  365 +
  366 + return navigator.push<T>(GetModalBottomSheetRoute<T>(
  367 + builder: (_) => bottomsheet,
  368 + theme: Theme.of(Get.key.currentContext, shadowThemeOnly: true),
  369 + isScrollControlled: isScrollControlled,
  370 + barrierLabel: MaterialLocalizations.of(Get.key.currentContext)
  371 + .modalBarrierDismissLabel,
  372 + backgroundColor: backgroundColor ?? Colors.transparent,
  373 + elevation: elevation,
  374 + shape: shape,
  375 + removeTop: ignoreSafeArea ?? true,
  376 + clipBehavior: clipBehavior,
  377 + isDismissible: isDismissible,
  378 + modalBarrierColor: barrierColor,
  379 + settings: RouteSettings(name: "bottomsheet"),
  380 + enableDrag: enableDrag,
  381 + ));
  382 + }
  383 +
  384 + static void rawSnackbar(
  385 + {String title,
  386 + String message,
  387 + Widget titleText,
  388 + Widget messageText,
  389 + Widget icon,
  390 + bool instantInit = false,
  391 + bool shouldIconPulse = true,
  392 + double maxWidth,
  393 + EdgeInsets margin = const EdgeInsets.all(0.0),
  394 + EdgeInsets padding = const EdgeInsets.all(16),
  395 + double borderRadius = 0.0,
  396 + Color borderColor,
  397 + double borderWidth = 1.0,
  398 + Color backgroundColor = const Color(0xFF303030),
  399 + Color leftBarIndicatorColor,
  400 + List<BoxShadow> boxShadows,
  401 + Gradient backgroundGradient,
  402 + FlatButton mainButton,
  403 + OnTap onTap,
  404 + Duration duration = const Duration(seconds: 3),
  405 + bool isDismissible = true,
  406 + SnackDismissDirection dismissDirection = SnackDismissDirection.VERTICAL,
  407 + bool showProgressIndicator = false,
  408 + AnimationController progressIndicatorController,
  409 + Color progressIndicatorBackgroundColor,
  410 + Animation<Color> progressIndicatorValueColor,
  411 + SnackPosition snackPosition = SnackPosition.BOTTOM,
  412 + SnackStyle snackStyle = SnackStyle.FLOATING,
  413 + Curve forwardAnimationCurve = Curves.easeOutCirc,
  414 + Curve reverseAnimationCurve = Curves.easeOutCirc,
  415 + Duration animationDuration = const Duration(seconds: 1),
  416 + SnackStatusCallback onStatusChanged,
  417 + double barBlur = 0.0,
  418 + double overlayBlur = 0.0,
  419 + Color overlayColor = Colors.transparent,
  420 + Form userInputForm}) {
  421 + GetBar getBar = GetBar(
  422 + title: title,
  423 + message: message,
  424 + titleText: titleText,
  425 + messageText: messageText,
  426 + snackPosition: snackPosition,
  427 + borderRadius: borderRadius,
  428 + margin: margin,
  429 + duration: duration,
  430 + barBlur: barBlur,
  431 + backgroundColor: backgroundColor,
  432 + icon: icon,
  433 + shouldIconPulse: shouldIconPulse,
  434 + maxWidth: maxWidth,
  435 + padding: padding,
  436 + borderColor: borderColor,
  437 + borderWidth: borderWidth,
  438 + leftBarIndicatorColor: leftBarIndicatorColor,
  439 + boxShadows: boxShadows,
  440 + backgroundGradient: backgroundGradient,
  441 + mainButton: mainButton,
  442 + onTap: onTap,
  443 + isDismissible: isDismissible,
  444 + dismissDirection: dismissDirection,
  445 + showProgressIndicator: showProgressIndicator ?? false,
  446 + progressIndicatorController: progressIndicatorController,
  447 + progressIndicatorBackgroundColor: progressIndicatorBackgroundColor,
  448 + progressIndicatorValueColor: progressIndicatorValueColor,
  449 + snackStyle: snackStyle,
  450 + forwardAnimationCurve: forwardAnimationCurve,
  451 + reverseAnimationCurve: reverseAnimationCurve,
  452 + animationDuration: animationDuration,
  453 + overlayBlur: overlayBlur,
  454 + overlayColor: overlayColor,
  455 + userInputForm: userInputForm);
  456 +
  457 + if (instantInit) {
  458 + getBar.show();
  459 + } else {
  460 + SchedulerBinding.instance.addPostFrameCallback((_) {
  461 + getBar.show();
  462 + });
  463 + }
  464 + }
  465 +
  466 + static void snackbar(title, message,
  467 + {Color colorText,
  468 + Duration duration,
  469 +
  470 + /// with instantInit = false you can put Get.snackbar on initState
  471 + bool instantInit = false,
  472 + SnackPosition snackPosition,
  473 + Widget titleText,
  474 + Widget messageText,
  475 + Widget icon,
  476 + bool shouldIconPulse,
  477 + double maxWidth,
  478 + EdgeInsets margin,
  479 + EdgeInsets padding,
  480 + double borderRadius,
  481 + Color borderColor,
  482 + double borderWidth,
  483 + Color backgroundColor,
  484 + Color leftBarIndicatorColor,
  485 + List<BoxShadow> boxShadows,
  486 + Gradient backgroundGradient,
  487 + FlatButton mainButton,
  488 + OnTap onTap,
  489 + bool isDismissible,
  490 + bool showProgressIndicator,
  491 + SnackDismissDirection dismissDirection,
  492 + AnimationController progressIndicatorController,
  493 + Color progressIndicatorBackgroundColor,
  494 + Animation<Color> progressIndicatorValueColor,
  495 + SnackStyle snackStyle,
  496 + Curve forwardAnimationCurve,
  497 + Curve reverseAnimationCurve,
  498 + Duration animationDuration,
  499 + double barBlur,
  500 + double overlayBlur,
  501 + Color overlayColor,
  502 + Form userInputForm}) {
  503 + GetBar getBar = GetBar(
  504 + titleText: (title == null)
  505 + ? null
  506 + : titleText ??
  507 + Text(
  508 + title,
  509 + style: TextStyle(
  510 + color: colorText ?? theme.iconTheme.color,
  511 + fontWeight: FontWeight.w800,
  512 + fontSize: 16),
  513 + ),
  514 + messageText: messageText ??
  515 + Text(
  516 + message,
  517 + style: TextStyle(
  518 + color: colorText ?? theme.iconTheme.color,
  519 + fontWeight: FontWeight.w300,
  520 + fontSize: 14),
  521 + ),
  522 + snackPosition: snackPosition ?? SnackPosition.TOP,
  523 + borderRadius: borderRadius ?? 15,
  524 + margin: margin ?? EdgeInsets.symmetric(horizontal: 10),
  525 + duration: duration ?? Duration(seconds: 3),
  526 + barBlur: barBlur ?? 7.0,
  527 + backgroundColor: backgroundColor ?? Colors.grey.withOpacity(0.2),
  528 + icon: icon,
  529 + shouldIconPulse: shouldIconPulse ?? true,
  530 + maxWidth: maxWidth,
  531 + padding: padding ?? EdgeInsets.all(16),
  532 + borderColor: borderColor,
  533 + borderWidth: borderWidth,
  534 + leftBarIndicatorColor: leftBarIndicatorColor,
  535 + boxShadows: boxShadows,
  536 + backgroundGradient: backgroundGradient,
  537 + mainButton: mainButton,
  538 + onTap: onTap,
  539 + isDismissible: isDismissible ?? true,
  540 + dismissDirection: dismissDirection ?? SnackDismissDirection.VERTICAL,
  541 + showProgressIndicator: showProgressIndicator ?? false,
  542 + progressIndicatorController: progressIndicatorController,
  543 + progressIndicatorBackgroundColor: progressIndicatorBackgroundColor,
  544 + progressIndicatorValueColor: progressIndicatorValueColor,
  545 + snackStyle: snackStyle ?? SnackStyle.FLOATING,
  546 + forwardAnimationCurve: forwardAnimationCurve ?? Curves.easeOutCirc,
  547 + reverseAnimationCurve: reverseAnimationCurve ?? Curves.easeOutCirc,
  548 + animationDuration: animationDuration ?? Duration(seconds: 1),
  549 + overlayBlur: overlayBlur ?? 0.0,
  550 + overlayColor: overlayColor ?? Colors.transparent,
  551 + userInputForm: userInputForm);
  552 +
  553 + if (instantInit) {
  554 + getBar.show();
  555 + } else {
  556 + SchedulerBinding.instance.addPostFrameCallback((_) {
  557 + getBar.show();
  558 + });
  559 + }
  560 + }
  561 +
  562 + /// change default config of Get
  563 + static void config(
  564 + {bool enableLog,
  565 + bool defaultPopGesture,
  566 + bool defaultOpaqueRoute,
  567 + Duration defaultDurationTransition,
  568 + bool defaultGlobalState,
  569 + Transition defaultTransition}) {
  570 + if (enableLog != null) {
  571 + _enableLog = enableLog;
  572 + }
  573 + if (defaultPopGesture != null) {
  574 + _defaultPopGesture = defaultPopGesture;
  575 + }
  576 + if (defaultOpaqueRoute != null) {
  577 + _defaultOpaqueRoute = defaultOpaqueRoute;
  578 + }
  579 + if (defaultTransition != null) {
  580 + _defaultTransition = defaultTransition;
  581 + }
  582 +
  583 + if (defaultDurationTransition != null) {
  584 + _defaultDurationTransition = defaultDurationTransition;
  585 + }
  586 +
  587 + if (defaultGlobalState != null) {
  588 + _defaultGlobalState = defaultGlobalState;
  589 + }
  590 + }
  591 +
  592 + static GetMaterialController getController = GetMaterialController();
  593 +
  594 + static changeTheme(ThemeData theme) {
  595 + getController.setTheme(theme);
  596 + }
  597 +
  598 + static restartApp() {
  599 + getController.restartApp();
  600 + }
  601 +
  602 + static Map<int, GlobalKey<NavigatorState>> _keys = {};
  603 +
  604 + static GlobalKey<NavigatorState> nestedKey(int key) {
  605 + _keys.putIfAbsent(key, () => GlobalKey<NavigatorState>());
  606 + return _keys[key];
  607 + }
  608 +
  609 + static GlobalKey<NavigatorState> global(int k) {
  610 + if (k == null) {
  611 + return key;
  612 + }
  613 + if (!_keys.containsKey(k)) {
  614 + throw 'route id not found';
  615 + }
  616 + return _keys[k];
  617 + }
  618 +
  619 + //////////// INSTANCE MANAGER
  620 + Map<dynamic, dynamic> _singl = {};
  621 +
  622 + Map<dynamic, _FcBuilderFunc> _factory = {};
  623 +
  624 + static void lazyPut<S>(_FcBuilderFunc function) {
  625 + Get()._factory.putIfAbsent(S, () => function);
  626 + }
  627 +
  628 + /// Inject class on Get Instance Manager
  629 + static S put<S>(
  630 + S dependency, {
  631 + String name,
  632 + bool overrideAbstract = false,
  633 + _FcBuilderFunc<S> builder,
  634 + }) {
  635 + _insert(
  636 + isSingleton: true,
  637 + replace: overrideAbstract,
  638 + //?? (("$S" == "${dependency.runtimeType}") == false),
  639 + name: name,
  640 + builder: builder ?? (() => dependency));
  641 + return find<S>(name: name);
  642 + }
  643 +
  644 + /// Create a new instance from builder class
  645 + /// Example
  646 + /// Get.create(() => Repl());
  647 + /// Repl a = Get.find();
  648 + /// Repl b = Get.find();
  649 + /// print(a==b); (false)
  650 + static void create<S>(
  651 + _FcBuilderFunc<S> builder, {
  652 + String name,
  653 + }) {
  654 + _insert(isSingleton: false, name: name, builder: builder);
  655 + }
  656 +
  657 + static void _insert<S>({
  658 + bool isSingleton,
  659 + String name,
  660 + bool replace = true,
  661 + _FcBuilderFunc<S> builder,
  662 + }) {
  663 + assert(builder != null);
  664 + String key = _getKey(S, name);
  665 + if (replace) {
  666 + Get()._singl[key] = _FcBuilder<S>(isSingleton, builder);
  667 + } else {
  668 + Get()._singl.putIfAbsent(key, () => _FcBuilder<S>(isSingleton, builder));
  669 + }
  670 + }
  671 +
  672 + /// Find a instance from required class
  673 + static S find<S>({String name}) {
  674 + if (Get.isRegistred<S>()) {
  675 + String key = _getKey(S, name);
  676 + _FcBuilder builder = Get()._singl[key];
  677 + if (builder == null) {
  678 + if (name == null) {
  679 + throw "class ${S.toString()} is not register";
  680 + } else {
  681 + throw "class ${S.toString()} with name '$name' is not register";
  682 + }
  683 + }
  684 + return Get()._singl[key].getSependency();
  685 + } else {
  686 + if (!Get()._factory.containsKey(S))
  687 + throw " $S not found. You need call Get.put<$S>($S()) before";
  688 +
  689 + if (isLogEnable) print('[GET] $S instance was created at that time');
  690 + S _value = Get.put<S>(Get()._factory[S].call() as S);
  691 + Get()._factory.remove(S);
  692 + return _value;
  693 + }
  694 + }
  695 +
  696 + /// Remove dependency of [S] on dependency abstraction. For concrete class use Get.delete
  697 + static void remove<S>({String name}) {
  698 + String key = _getKey(S, name);
  699 + _FcBuilder builder = Get()._singl[key];
  700 + if (builder != null) builder.dependency = null;
  701 + if (Get()._singl.containsKey(key)) {
  702 + print('error on remove $key');
  703 + } else {
  704 + if (isLogEnable) print('[GET] $key removed from memory');
  705 + }
  706 + }
  707 +
  708 + static String _getKey(Type type, String name) {
  709 + return name == null ? type.toString() : type.toString() + name;
  710 + }
  711 +
  712 + static bool reset() {
  713 + Get()._singl.clear();
  714 + return true;
  715 + }
  716 +
  717 + /// Delete class instance on [S] and clean memory
  718 + static bool delete<S>({String name}) {
  719 + String key = _getKey(S, name);
  720 +
  721 + if (!Get()._singl.containsKey(key)) {
  722 + print('Instance $key not found');
  723 + return false;
  724 + }
  725 + Get()._singl.removeWhere((oldkey, value) => (oldkey == key));
  726 + if (Get()._singl.containsKey(key)) {
  727 + print('error on remove object $key');
  728 + } else {
  729 + if (isLogEnable) print('[GET] $key deleted from memory');
  730 + }
  731 + return true;
  732 + }
  733 +
  734 + /// check if instance is registred
  735 + static bool isRegistred<S>({String name}) =>
  736 + Get()._singl.containsKey(_getKey(S, name));
  737 +
  738 + /// give access to Routing API from GetObserver
  739 + static Routing get routing => _routing;
  740 +
  741 + static RouteSettings get routeSettings => _settings;
  742 +
  743 + static Routing _routing;
  744 +
  745 + static Map<String, String> _parameters = {};
  746 +
  747 + static setParameter(Map<String, String> param) {
  748 + _parameters = param;
  749 + }
  750 +
  751 + static setRouting(Routing rt) {
  752 + _routing = rt;
  753 + }
  754 +
  755 + static setSettings(RouteSettings settings) {
  756 + _settings = settings;
  757 + }
  758 +
  759 + /// give current arguments
  760 + static get arguments => _routing.args;
  761 +
  762 + /// give current arguments
  763 + static Map<String, String> get parameters => _parameters;
  764 +
  765 + /// interface to GetX
  766 + RxInterface _obs;
  767 +
  768 + static RxInterface get obs => _get._obs;
  769 +
  770 + static set obs(RxInterface observer) => _get._obs = observer;
  771 +
  772 + /// give arguments from previous route
  773 + static get previousArguments => _routing.previousArgs;
  774 +
  775 + /// give name from current route
  776 + static get currentRoute => _routing.current;
  777 +
  778 + /// give name from previous route
  779 + static get previousRoute => _routing.previous;
  780 +
  781 + /// check if snackbar is open
  782 + static bool get isSnackbarOpen => _routing.isSnackbar;
  783 +
  784 + /// check if dialog is open
  785 + static bool get isDialogOpen => _routing.isDialog;
  786 +
  787 + /// check if bottomsheet is open
  788 + static bool get isBottomSheetOpen => _routing.isBottomSheet;
  789 +
  790 + /// check a raw current route
  791 + static Route<dynamic> get rawRoute => _routing.route;
  792 +
  793 + /// check if log is enable
  794 + static bool get isLogEnable => _enableLog;
  795 +
  796 + /// default duration of transition animation
  797 + /// default duration work only API 2.0
  798 + static Duration get defaultDurationTransition => _defaultDurationTransition;
  799 +
  800 + /// give global state of all GetState by default
  801 + static bool get defaultGlobalState => _defaultGlobalState;
  802 +
  803 + /// check if popGesture is enable
  804 + static bool get isPopGestureEnable => _defaultPopGesture;
  805 +
  806 + /// check if default opaque route is enable
  807 + static bool get isOpaqueRouteDefault => _defaultOpaqueRoute;
  808 +
  809 + static Transition get defaultTransition => _defaultTransition;
  810 +
  811 + /// give access to currentContext
  812 + static BuildContext get context => key.currentContext;
  813 +
  814 + /// give access to current Overlay Context
  815 + static BuildContext get overlayContext => key.currentState.overlay.context;
  816 +
  817 + /// give access to Theme.of(context)
  818 + static ThemeData get theme => Theme.of(context);
  819 +
  820 + /// give access to TextTheme.of(context)
  821 + static TextTheme get textTheme => Theme.of(context).textTheme;
  822 +
  823 + /// give access to Mediaquery.of(context)
  824 + static MediaQueryData get mediaQuery => MediaQuery.of(context);
  825 +
  826 + /// Check if dark mode theme is enable
  827 + static get isDarkMode => (theme.brightness == Brightness.dark);
  828 +
  829 + /// Check if dark mode theme is enable on platform on android Q+
  830 + static get isPlatformDarkMode =>
  831 + (mediaQuery.platformBrightness == Brightness.dark);
  832 +
  833 + /// give access to Theme.of(context).iconTheme.color
  834 + static Color get iconColor => Theme.of(context).iconTheme.color;
  835 +
  836 + /// give access to MediaQuery.of(context).size.height
  837 + static double get height => MediaQuery.of(context).size.height;
  838 +
  839 + /// give access to MediaQuery.of(context).size.width
  840 + static double get width => MediaQuery.of(context).size.width;
  841 +}
  842 +
  843 +/// It replaces the Flutter Navigator, but needs no context.
  844 +/// You can to use navigator.push(YourRoute()) rather Navigator.push(context, YourRoute());
  845 +NavigatorState get navigator => Get.key.currentState;
  846 +
  847 +class _FcBuilder<S> {
  848 + bool isSingleton;
  849 + _FcBuilderFunc builderFunc;
  850 + S dependency;
  851 +
  852 + _FcBuilder(this.isSingleton, this.builderFunc);
  853 +
  854 + S getSependency() {
  855 + if (isSingleton) {
  856 + if (dependency == null) {
  857 + dependency = builderFunc() as S;
  858 + }
  859 + return dependency;
  860 + } else {
  861 + return builderFunc() as S;
  862 + }
  863 + }
  864 +}
  865 +
  866 +typedef _FcBuilderFunc<S> = S Function();
@@ -5,6 +5,7 @@ import 'package:get/src/routes/utils/parse_arguments.dart'; @@ -5,6 +5,7 @@ import 'package:get/src/routes/utils/parse_arguments.dart';
5 import 'root_controller.dart'; 5 import 'root_controller.dart';
6 6
7 class GetMaterialApp extends StatelessWidget { 7 class GetMaterialApp extends StatelessWidget {
  8 +
8 const GetMaterialApp({ 9 const GetMaterialApp({
9 Key key, 10 Key key,
10 this.navigatorKey, 11 this.navigatorKey,
@@ -99,13 +100,12 @@ class GetMaterialApp extends StatelessWidget { @@ -99,13 +100,12 @@ class GetMaterialApp extends StatelessWidget {
99 100
100 Route<dynamic> namedRoutesGenerate(RouteSettings settings) { 101 Route<dynamic> namedRoutesGenerate(RouteSettings settings) {
101 Get.setSettings(settings); 102 Get.setSettings(settings);
102 - // final parsedString = parse.split(settings.name);  
103 103
104 /// onGenerateRoute to FlutterWeb is Broken on Dev/Master. This is a temporary 104 /// onGenerateRoute to FlutterWeb is Broken on Dev/Master. This is a temporary
105 /// workaround until they fix it, because the problem is with the 'Flutter engine', 105 /// workaround until they fix it, because the problem is with the 'Flutter engine',
106 /// which changes the initial route for an empty String, not the main Flutter, 106 /// which changes the initial route for an empty String, not the main Flutter,
107 /// so only Team can fix it. 107 /// so only Team can fix it.
108 - var parsedString = Get.getController.parse.split( 108 + var parsedString = Get().getController.parse.split(
109 (settings.name == '' || settings.name == null) 109 (settings.name == '' || settings.name == null)
110 ? (initialRoute ?? '/') 110 ? (initialRoute ?? '/')
111 : settings.name); 111 : settings.name);
@@ -119,7 +119,7 @@ class GetMaterialApp extends StatelessWidget { @@ -119,7 +119,7 @@ class GetMaterialApp extends StatelessWidget {
119 Map<String, GetRoute> newNamedRoutes = {}; 119 Map<String, GetRoute> newNamedRoutes = {};
120 120
121 namedRoutes.forEach((key, value) { 121 namedRoutes.forEach((key, value) {
122 - String newName = Get.getController.parse.split(key).route; 122 + String newName = Get().getController.parse.split(key).route;
123 newNamedRoutes.addAll({newName: value}); 123 newNamedRoutes.addAll({newName: value});
124 }); 124 });
125 125
@@ -171,7 +171,7 @@ class GetMaterialApp extends StatelessWidget { @@ -171,7 +171,7 @@ class GetMaterialApp extends StatelessWidget {
171 @override 171 @override
172 Widget build(BuildContext context) { 172 Widget build(BuildContext context) {
173 return GetBuilder<GetMaterialController>( 173 return GetBuilder<GetMaterialController>(
174 - init: Get.getController, 174 + init: Get().getController,
175 dispose: (d) { 175 dispose: (d) {
176 onDispose?.call(); 176 onDispose?.call();
177 }, 177 },
@@ -179,7 +179,7 @@ class GetMaterialApp extends StatelessWidget { @@ -179,7 +179,7 @@ class GetMaterialApp extends StatelessWidget {
179 onInit?.call(); 179 onInit?.call();
180 if (namedRoutes != null) { 180 if (namedRoutes != null) {
181 namedRoutes.forEach((key, value) { 181 namedRoutes.forEach((key, value) {
182 - Get.getController.parse.addRoute(key); 182 + Get().getController.parse.addRoute(key);
183 }); 183 });
184 } 184 }
185 Get.config( 185 Get.config(
@@ -212,7 +212,7 @@ class GetMaterialApp extends StatelessWidget { @@ -212,7 +212,7 @@ class GetMaterialApp extends StatelessWidget {
212 title: title ?? '', 212 title: title ?? '',
213 onGenerateTitle: onGenerateTitle, 213 onGenerateTitle: onGenerateTitle,
214 color: color, 214 color: color,
215 - theme: theme ?? _.theme ?? ThemeData.fallback(), 215 + theme: _.theme ?? theme ?? ThemeData.fallback(),
216 darkTheme: darkTheme, 216 darkTheme: darkTheme,
217 themeMode: themeMode ?? ThemeMode.system, 217 themeMode: themeMode ?? ThemeMode.system,
218 locale: locale, 218 locale: locale,
  1 +typedef void ValueCallback<T>(T v);
  1 +import 'dart:async';
  2 +import 'package:flutter/widgets.dart';
  3 +import 'package:get/src/get_main.dart';
  4 +import 'rx_impl.dart';
  5 +import 'rx_interface.dart';
  6 +
  7 +class GetX<T extends RxController> extends StatefulWidget {
  8 + final Widget Function(T) builder;
  9 + final bool global;
  10 + final Stream Function(T) stream;
  11 + final StreamController Function(T) streamController;
  12 + final bool autoRemove;
  13 + final void Function(State state) initState, dispose, didChangeDependencies;
  14 + final T init;
  15 + GetX(
  16 + {this.builder,
  17 + this.global = true,
  18 + this.autoRemove = true,
  19 + this.initState,
  20 + this.stream,
  21 + this.dispose,
  22 + this.didChangeDependencies,
  23 + this.init,
  24 + this.streamController});
  25 + _GetXState<T> createState() => _GetXState<T>();
  26 +}
  27 +
  28 +class _GetXState<T extends RxController> extends State<GetX<T>> {
  29 + RxInterface _observer;
  30 + StreamSubscription _listenSubscription;
  31 + T controller;
  32 +
  33 + _GetXState() {
  34 + _observer = Rx();
  35 + }
  36 +
  37 + @override
  38 + void initState() {
  39 + if (widget.global) {
  40 + if (Get.isRegistred<T>()) {
  41 + controller = Get.find<T>();
  42 + } else {
  43 + controller = widget.init;
  44 + Get.put<T>(controller);
  45 + }
  46 + } else {
  47 + controller = widget.init;
  48 + }
  49 + if (widget.initState != null) widget.initState(this);
  50 + try {
  51 + controller?.onInit();
  52 + } catch (e) {
  53 + if (Get.isLogEnable) print("Failure on call onInit");
  54 + }
  55 + _listenSubscription = _observer.subject.stream.listen((data) {
  56 + setState(() {});
  57 + });
  58 + super.initState();
  59 + }
  60 +
  61 + @override
  62 + void dispose() {
  63 + controller?.close();
  64 + _listenSubscription?.cancel();
  65 + _observer?.close();
  66 + super.dispose();
  67 + }
  68 +
  69 + @override
  70 + Widget build(BuildContext context) {
  71 + _observer.close();
  72 + final observer = Get.obs;
  73 + Get.obs = this._observer;
  74 + final result = widget.builder(controller);
  75 + Get.obs = observer;
  76 + return result;
  77 + }
  78 +}
  1 +import 'dart:async';
  2 +import 'package:get/src/get_main.dart';
  3 +import 'rx_callbacks.dart';
  4 +import 'rx_interface.dart';
  5 +import 'rx_model.dart';
  6 +import 'utils/delegate_list.dart';
  7 +
  8 +class _StoredValue<T> implements RxInterface<T> {
  9 + StreamController<Change<T>> subject = StreamController<Change<T>>.broadcast();
  10 + StreamController<Change<T>> _changeCtl = StreamController<Change<T>>();
  11 + Map<Stream<Change<T>>, StreamSubscription> _subscriptions = Map();
  12 +
  13 + T _value;
  14 + T get value {
  15 + if (Get.obs != null) {
  16 + Get.obs.addListener(subject.stream);
  17 + }
  18 + return _value;
  19 + }
  20 +
  21 + String get string => value.toString();
  22 +
  23 + close() {
  24 + _subscriptions.forEach((observable, subscription) {
  25 + subscription.cancel();
  26 + });
  27 + _subscriptions.clear();
  28 + _changeCtl.close();
  29 + }
  30 +
  31 + addListener(Stream<Change<T>> rxGetx) {
  32 + if (_subscriptions.containsKey(rxGetx)) {
  33 + return;
  34 + }
  35 +
  36 + _subscriptions[rxGetx] = rxGetx.listen((data) {
  37 + subject.add(data);
  38 + });
  39 + }
  40 +
  41 + set value(T val) {
  42 + if (_value == val) return;
  43 + T old = _value;
  44 + _value = val;
  45 + subject.add(Change<T>($new: val, $old: old, batch: _cb));
  46 + }
  47 +
  48 + int _cb = 0;
  49 +
  50 + _StoredValue([T initial]) : _value = initial {
  51 + _onChange = subject.stream.asBroadcastStream();
  52 + }
  53 +
  54 + void setCast(dynamic /* T */ val) => value = val;
  55 +
  56 + Stream<Change<T>> _onChange;
  57 +
  58 + Stream<Change<T>> get onChange {
  59 + _cb++;
  60 +
  61 + _changeCtl.add(Change<T>($new: value, $old: null, batch: _cb));
  62 + _changeCtl.addStream(_onChange.skipWhile((v) => v.batch < _cb));
  63 + return _changeCtl.stream.asBroadcastStream();
  64 + }
  65 +
  66 + Stream<T> get stream => onChange.map((c) => c.$new);
  67 +
  68 + void bind(RxInterface<T> reactive) {
  69 + value = reactive.value;
  70 + reactive.stream.listen((v) => value = v);
  71 + }
  72 +
  73 + void bindStream(Stream<T> stream) => stream.listen((v) => value = v);
  74 +
  75 + void bindOrSet(/* T | Stream<T> | Reactive<T> */ other) {
  76 + if (other is RxInterface<T>) {
  77 + bind(other);
  78 + } else if (other is Stream<T>) {
  79 + bindStream(other.cast<T>());
  80 + } else {
  81 + value = other;
  82 + }
  83 + }
  84 +
  85 + StreamSubscription<T> listen(ValueCallback<T> callback) =>
  86 + stream.listen(callback);
  87 +
  88 + Stream<R> map<R>(R mapper(T data)) => stream.map(mapper);
  89 +}
  90 +
  91 +class StringX<String> extends _StoredValue<String> {
  92 + StringX([String initial]) {
  93 + _value = initial;
  94 + _onChange = subject.stream.asBroadcastStream();
  95 + }
  96 +}
  97 +
  98 +class IntX<int> extends _StoredValue<int> {
  99 + IntX([int initial]) {
  100 + _value = initial;
  101 + _onChange = subject.stream.asBroadcastStream();
  102 + }
  103 +}
  104 +
  105 +class MapX<Map> extends _StoredValue<Map> {
  106 + MapX([Map initial]) {
  107 + _value = initial;
  108 + _onChange = subject.stream.asBroadcastStream();
  109 + }
  110 +}
  111 +
  112 +// class ListX<List> extends _StoredValue<List> {
  113 +// ListX([List initial]) {
  114 +// _value = initial;
  115 +// _onChange = subject.stream.asBroadcastStream();
  116 +// }
  117 +// }
  118 +
  119 +class ListX<E> extends DelegatingList<E> implements List<E>, RxInterface<E> {
  120 + /// Create a list similar to `List<T>`
  121 + ListX([int length]) : super(length != null ? List<E>(length) : List<E>()) {
  122 + _onChange = subject.stream.asBroadcastStream();
  123 + }
  124 +
  125 + ListX.filled(int length, E fill, {bool growable: false})
  126 + : super(List<E>.filled(length, fill, growable: growable)) {
  127 + _onChange = subject.stream.asBroadcastStream();
  128 + }
  129 +
  130 + ListX.from(Iterable<E> items, {bool growable: true})
  131 + : super(List<E>.from(items, growable: growable)) {
  132 + _onChange = subject.stream.asBroadcastStream();
  133 + }
  134 +
  135 + ListX.union(Iterable<E> items, [E item]) : super(items?.toList() ?? <E>[]) {
  136 + if (item != null) add(item);
  137 + _onChange = subject.stream.asBroadcastStream();
  138 + }
  139 +
  140 + ListX.of(Iterable<E> items, {bool growable: true})
  141 + : super(List<E>.of(items, growable: growable));
  142 +
  143 + ListX.generate(int length, E generator(int index), {bool growable: true})
  144 + : super(List<E>.generate(length, generator, growable: growable));
  145 +
  146 + Map<Stream<Change<E>>, StreamSubscription> _subscriptions = Map();
  147 +
  148 + final _changeCtl = StreamController<Change<E>>();
  149 +
  150 + /// Adds [item] only if [condition] resolves to true.
  151 + void addIf(condition, E item) {
  152 + if (condition is Condition) condition = condition();
  153 + if (condition is bool && condition) add(item);
  154 + }
  155 +
  156 + /// Adds all [items] only if [condition] resolves to true.
  157 + void addAllIf(condition, Iterable<E> items) {
  158 + if (condition is Condition) condition = condition();
  159 + if (condition is bool && condition) addAll(items);
  160 + }
  161 +
  162 + operator []=(int index, E value) {
  163 + super[index] = value;
  164 + subject.add(Change<E>.set(item: value, pos: index));
  165 + }
  166 +
  167 + void _add(E item) => super.add(item);
  168 +
  169 + void add(E item) {
  170 + super.add(item);
  171 + subject.add(Change<E>.insert(item: item, pos: length - 1));
  172 + }
  173 +
  174 + /// Adds only if [item] is not null.
  175 + void addNonNull(E item) {
  176 + if (item != null) add(item);
  177 + }
  178 +
  179 + void insert(int index, E item) {
  180 + super.insert(index, item);
  181 + subject.add(Change<E>.insert(item: item, pos: index));
  182 + }
  183 +
  184 + bool remove(Object item) {
  185 + int pos = indexOf(item);
  186 + bool hasRemoved = super.remove(item);
  187 + if (hasRemoved) {
  188 + subject.add(Change<E>.remove(item: item, pos: pos));
  189 + }
  190 + return hasRemoved;
  191 + }
  192 +
  193 + void clear() {
  194 + super.clear();
  195 + subject.add(Change<E>.clear());
  196 + }
  197 +
  198 + close() {
  199 + _subscriptions.forEach((observable, subscription) {
  200 + subscription.cancel();
  201 + });
  202 + _subscriptions.clear();
  203 + subject.close();
  204 + _changeCtl.close();
  205 + }
  206 +
  207 + /// Replaces all existing items of this list with [item]
  208 + void assign(E item) {
  209 + clear();
  210 + add(item);
  211 + }
  212 +
  213 + /// Replaces all existing items of this list with [items]
  214 + void assignAll(Iterable<E> items) {
  215 + clear();
  216 + addAll(items);
  217 + }
  218 +
  219 + /// A stream of record of changes to this list
  220 + Stream<Change<E>> get onChange {
  221 + final now = DateTime.now();
  222 + _changeCtl.addStream(_onChange.skipWhile((m) => m.time.isBefore(now)));
  223 + return _changeCtl.stream.asBroadcastStream();
  224 + }
  225 +
  226 + Stream<Change<E>> _onChange;
  227 +
  228 + @override
  229 + StreamController<Change<E>> subject = StreamController<Change<E>>();
  230 +
  231 + addListener(Stream<Change<E>> rxGetx) {
  232 + if (_subscriptions.containsKey(rxGetx)) {
  233 + return;
  234 + }
  235 + _subscriptions[rxGetx] = rxGetx.listen((data) {
  236 + subject.add(data);
  237 + });
  238 + }
  239 +
  240 + @override
  241 + var value;
  242 +
  243 + @override
  244 + Stream<E> get stream => onChange.map((c) => c.item);
  245 +
  246 + @override
  247 + void bind(RxInterface<E> reactive) {
  248 + value = reactive.value;
  249 + reactive.stream.listen((v) => value = v);
  250 + }
  251 +
  252 + void bindStream(Stream<E> stream) => stream.listen((v) => value = v);
  253 +
  254 + @override
  255 + void bindOrSet(/* T | Stream<T> | Rx<T> */ other) {
  256 + if (other is RxInterface<E>) {
  257 + bind(other);
  258 + } else if (other is Stream<E>) {
  259 + bindStream(other.cast<E>());
  260 + } else {
  261 + value = other;
  262 + }
  263 + }
  264 +
  265 + @override
  266 + StreamSubscription<E> listen(ValueCallback<E> callback) =>
  267 + stream.listen(callback);
  268 +
  269 + @override
  270 + void setCast(dynamic /* T */ val) => value = val;
  271 +}
  272 +
  273 +typedef bool Condition();
  274 +
  275 +typedef E ChildrenListComposer<S, E>(S value);
  276 +
  277 +/// An observable list that is bound to another list [binding]
  278 +class BoundList<S, E> extends ListX<E> {
  279 + final ListX<S> binding;
  280 +
  281 + final ChildrenListComposer<S, E> composer;
  282 +
  283 + BoundList(this.binding, this.composer) {
  284 + for (S v in binding) _add(composer(v));
  285 + binding.onChange.listen((Change<S> n) {
  286 + if (n.op == ListChangeOp.add) {
  287 + insert(n.pos, composer(n.item));
  288 + } else if (n.op == ListChangeOp.remove) {
  289 + removeAt(n.pos);
  290 + } else if (n.op == ListChangeOp.clear) {
  291 + clear();
  292 + }
  293 + });
  294 + }
  295 +}
  296 +
  297 +class BoolX<bool> extends _StoredValue<bool> {
  298 + BoolX([bool initial]) {
  299 + _value = initial;
  300 + _onChange = subject.stream.asBroadcastStream();
  301 + }
  302 +}
  303 +
  304 +class DoubleX<double> extends _StoredValue<double> {
  305 + DoubleX([double initial]) {
  306 + _value = initial;
  307 + _onChange = subject.stream.asBroadcastStream();
  308 + }
  309 +}
  310 +
  311 +class NumX<num> extends _StoredValue<num> {
  312 + NumX([num initial]) {
  313 + _value = initial;
  314 + _onChange = subject.stream.asBroadcastStream();
  315 + }
  316 +}
  317 +
  318 +class Rx<T> extends _StoredValue<T> {
  319 + Rx([T initial]) {
  320 + _value = initial;
  321 + _onChange = subject.stream.asBroadcastStream();
  322 + }
  323 +}
  324 +
  325 +extension StringExtension on String {
  326 + StringX<String> get obs {
  327 + if (this != null)
  328 + return StringX(this);
  329 + else
  330 + return StringX(null);
  331 + }
  332 +}
  333 +
  334 +extension IntExtension on int {
  335 + IntX<int> get obs {
  336 + if (this != null)
  337 + return IntX(this);
  338 + else
  339 + return IntX(null);
  340 + }
  341 +}
  342 +
  343 +extension DoubleExtension on double {
  344 + DoubleX<double> get obs {
  345 + if (this != null)
  346 + return DoubleX(this);
  347 + else
  348 + return DoubleX(null);
  349 + }
  350 +}
  351 +
  352 +extension MapExtension on Map {
  353 + MapX<Map> get obs {
  354 + if (this != null)
  355 + return MapX(this);
  356 + else
  357 + return MapX(null);
  358 + }
  359 +}
  360 +
  361 +extension ListExtension on List {
  362 + ListX get obs {
  363 + if (this != null)
  364 + return ListX()..assignAll(this);
  365 + else
  366 + return ListX(null);
  367 + }
  368 +}
  369 +
  370 +extension BoolExtension on bool {
  371 + BoolX<bool> get obs {
  372 + if (this != null)
  373 + return BoolX(this);
  374 + else
  375 + return BoolX(null);
  376 + }
  377 +}
  378 +
  379 +extension ObjectExtension on Object {
  380 + Rx<Object> get obs {
  381 + if (this != null)
  382 + return Rx(this);
  383 + else
  384 + return Rx(null);
  385 + }
  386 +}
  1 +import 'dart:async';
  2 +import 'package:get/src/rx/rx_callbacks.dart';
  3 +import 'package:get/src/rx/rx_model.dart';
  4 +
  5 +abstract class RxInterface<T> {
  6 + RxInterface([T initial]);
  7 +
  8 + /// Get current value
  9 + T get value;
  10 +
  11 + /// Set value
  12 + set value(T val);
  13 +
  14 + /// Cast [val] to [T] before setting
  15 + void setCast(dynamic /* T */ val);
  16 +
  17 + /// Stream of record of [Change]s of value
  18 + Stream<Change<T>> get onChange;
  19 +
  20 + /// add listener to stream
  21 + addListener(Stream<Change<T>> rxGetx);
  22 +
  23 + /// close stream
  24 + close() {
  25 + subject?.close();
  26 + }
  27 +
  28 + StreamController<Change<T>> subject;
  29 +
  30 + /// Stream of changes of value
  31 + Stream<T> get stream;
  32 +
  33 + /// Convert value on string
  34 + // String get string;
  35 +
  36 + /// Binds if [other] is [Stream] or [RxInterface] of type [T]. Sets if [other] is
  37 + /// instance of [T]
  38 + void bindOrSet(/* T | Stream<T> | Reactive<T> */ other);
  39 +
  40 + /// Binds [other] to this
  41 + void bind(RxInterface<T> other);
  42 +
  43 + /// Binds the [stream] to this
  44 + void bindStream(Stream<T> stream);
  45 +
  46 + /// Calls [callback] with current value, when the value changes.
  47 + StreamSubscription<T> listen(ValueCallback<T> callback);
  48 +
  49 + /// Maps the changes into a [Stream] of [S]
  50 + // Stream<S> map<S>(S mapper(T data));
  51 +}
  52 +
  53 +class RxController implements DisposableInterface {
  54 + void onInit() async {}
  55 + void close() async {}
  56 +}
  57 +
  58 +abstract class DisposableInterface {
  59 + void close() async {}
  60 + void onInit() async {}
  61 +}
  1 +import 'dart:async';
  2 +import 'package:flutter/widgets.dart';
  3 +import 'package:get/src/get_main.dart';
  4 +import 'rx_impl.dart';
  5 +import 'rx_interface.dart';
  6 +
  7 +class ListViewX<T extends RxController> extends StatefulWidget {
  8 + final Widget Function(T, int) builder;
  9 + final bool global;
  10 + final ListX Function(T) list;
  11 + final bool autoRemove;
  12 + final void Function(State state) initState, dispose, didChangeDependencies;
  13 + final T init;
  14 + final int itemCount;
  15 + ListViewX({
  16 + this.builder,
  17 + this.global = true,
  18 + this.autoRemove = true,
  19 + this.initState,
  20 + @required this.list,
  21 + this.itemCount,
  22 + this.dispose,
  23 + this.didChangeDependencies,
  24 + this.init,
  25 + });
  26 + _ListViewXState<T> createState() => _ListViewXState<T>();
  27 +}
  28 +
  29 +class _ListViewXState<T extends RxController> extends State<ListViewX<T>> {
  30 + RxInterface _observer;
  31 + StreamSubscription _listenSubscription;
  32 + T controller;
  33 +
  34 + _ListViewXState() {
  35 + _observer = ListX();
  36 + }
  37 +
  38 + @override
  39 + void initState() {
  40 + if (widget.global) {
  41 + if (Get.isRegistred<T>()) {
  42 + controller = Get.find<T>();
  43 + } else {
  44 + controller = widget.init;
  45 + Get.put<T>(controller);
  46 + }
  47 + } else {
  48 + controller = widget.init;
  49 + }
  50 + if (widget.initState != null) widget.initState(this);
  51 + try {
  52 + controller?.onInit();
  53 + } catch (e) {
  54 + if (Get.isLogEnable) print("Failure on call onInit");
  55 + }
  56 +
  57 + _listenSubscription = widget.list.call(controller).listen((data) {
  58 + setState(() {});
  59 + });
  60 + super.initState();
  61 + }
  62 +
  63 + @override
  64 + void dispose() {
  65 + controller?.close();
  66 + _listenSubscription?.cancel();
  67 + _observer?.close();
  68 + super.dispose();
  69 + }
  70 +
  71 + @override
  72 + Widget build(BuildContext context) {
  73 + _observer.close();
  74 + final observer = Get.obs;
  75 + Get.obs = this._observer;
  76 + final result = ListView.builder(
  77 + itemCount: widget.itemCount ?? widget.list.call(controller).length,
  78 + itemBuilder: (context, index) {
  79 + return widget.builder(controller, index);
  80 + });
  81 + Get.obs = observer;
  82 + return result;
  83 + }
  84 +}
  1 +class Change<T> {
  2 + /// Value before change
  3 + final T $old;
  4 +
  5 + /// Value after change
  6 + final T $new;
  7 +
  8 + final T item;
  9 +
  10 + final ListChangeOp op;
  11 +
  12 + final int pos;
  13 +
  14 + final DateTime time;
  15 + final int batch;
  16 + Change(
  17 + {this.$new,
  18 + this.$old,
  19 + this.batch,
  20 + this.item,
  21 + this.op,
  22 + this.pos,
  23 + DateTime time})
  24 + : time = time ?? DateTime.now();
  25 + String toString() => 'Change(new: ${$new}, old: ${$old})';
  26 +
  27 + Change.insert(
  28 + {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time})
  29 + : op = ListChangeOp.add,
  30 + time = time ?? new DateTime.now();
  31 +
  32 + Change.set(
  33 + {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time})
  34 + : op = ListChangeOp.set,
  35 + time = time ?? new DateTime.now();
  36 +
  37 + Change.remove(
  38 + {this.$new, this.$old, this.batch, this.item, this.pos, DateTime time})
  39 + : op = ListChangeOp.remove,
  40 + time = time ?? new DateTime.now();
  41 +
  42 + Change.clear({this.$new, this.$old, this.batch, DateTime time})
  43 + : op = ListChangeOp.clear,
  44 + pos = null,
  45 + item = null,
  46 + time = time ?? new DateTime.now();
  47 +}
  48 +
  49 +typedef bool Condition();
  50 +
  51 +typedef E ChildrenListComposer<S, E>(S value);
  52 +
  53 +/// Change operation
  54 +enum ListChangeOp { add, remove, clear, set }
  1 +import 'dart:math' as math;
  2 +
  3 +class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
  4 + const DelegatingList(List<E> base) : super(base);
  5 +
  6 + List<E> get _listBase => _base;
  7 +
  8 + E operator [](int index) => _listBase[index];
  9 +
  10 + void operator []=(int index, E value) {
  11 + _listBase[index] = value;
  12 + }
  13 +
  14 + List<E> operator +(List<E> other) => _listBase + other;
  15 +
  16 + void add(E value) {
  17 + _listBase.add(value);
  18 + }
  19 +
  20 + void addAll(Iterable<E> iterable) {
  21 + _listBase.addAll(iterable);
  22 + }
  23 +
  24 + Map<int, E> asMap() => _listBase.asMap();
  25 +
  26 + List<T> cast<T>() => _listBase.cast<T>();
  27 +
  28 + void clear() {
  29 + _listBase.clear();
  30 + }
  31 +
  32 + void fillRange(int start, int end, [E fillValue]) {
  33 + _listBase.fillRange(start, end, fillValue);
  34 + }
  35 +
  36 + set first(E value) {
  37 + if (this.isEmpty) throw RangeError.index(0, this);
  38 + this[0] = value;
  39 + }
  40 +
  41 + Iterable<E> getRange(int start, int end) => _listBase.getRange(start, end);
  42 +
  43 + int indexOf(E element, [int start = 0]) => _listBase.indexOf(element, start);
  44 +
  45 + int indexWhere(bool test(E element), [int start = 0]) =>
  46 + _listBase.indexWhere(test, start);
  47 +
  48 + void insert(int index, E element) {
  49 + _listBase.insert(index, element);
  50 + }
  51 +
  52 + insertAll(int index, Iterable<E> iterable) {
  53 + _listBase.insertAll(index, iterable);
  54 + }
  55 +
  56 + set last(E value) {
  57 + if (this.isEmpty) throw RangeError.index(0, this);
  58 + this[this.length - 1] = value;
  59 + }
  60 +
  61 + int lastIndexOf(E element, [int start]) =>
  62 + _listBase.lastIndexOf(element, start);
  63 +
  64 + int lastIndexWhere(bool test(E element), [int start]) =>
  65 + _listBase.lastIndexWhere(test, start);
  66 +
  67 + set length(int newLength) {
  68 + _listBase.length = newLength;
  69 + }
  70 +
  71 + bool remove(Object value) => _listBase.remove(value);
  72 +
  73 + E removeAt(int index) => _listBase.removeAt(index);
  74 +
  75 + E removeLast() => _listBase.removeLast();
  76 +
  77 + void removeRange(int start, int end) {
  78 + _listBase.removeRange(start, end);
  79 + }
  80 +
  81 + void removeWhere(bool test(E element)) {
  82 + _listBase.removeWhere(test);
  83 + }
  84 +
  85 + void replaceRange(int start, int end, Iterable<E> iterable) {
  86 + _listBase.replaceRange(start, end, iterable);
  87 + }
  88 +
  89 + void retainWhere(bool test(E element)) {
  90 + _listBase.retainWhere(test);
  91 + }
  92 +
  93 + @deprecated
  94 + List<T> retype<T>() => cast<T>();
  95 +
  96 + Iterable<E> get reversed => _listBase.reversed;
  97 +
  98 + void setAll(int index, Iterable<E> iterable) {
  99 + _listBase.setAll(index, iterable);
  100 + }
  101 +
  102 + void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
  103 + _listBase.setRange(start, end, iterable, skipCount);
  104 + }
  105 +
  106 + void shuffle([math.Random random]) {
  107 + _listBase.shuffle(random);
  108 + }
  109 +
  110 + void sort([int compare(E a, E b)]) {
  111 + _listBase.sort(compare);
  112 + }
  113 +
  114 + List<E> sublist(int start, [int end]) => _listBase.sublist(start, end);
  115 +}
  116 +
  117 +class DelegatingIterable<E> extends _DelegatingIterableBase<E> {
  118 + final Iterable<E> _base;
  119 +
  120 + const DelegatingIterable(Iterable<E> base) : _base = base;
  121 +}
  122 +
  123 +abstract class _DelegatingIterableBase<E> implements Iterable<E> {
  124 + Iterable<E> get _base;
  125 +
  126 + const _DelegatingIterableBase();
  127 +
  128 + bool any(bool test(E element)) => _base.any(test);
  129 +
  130 + Iterable<T> cast<T>() => _base.cast<T>();
  131 +
  132 + bool contains(Object element) => _base.contains(element);
  133 +
  134 + E elementAt(int index) => _base.elementAt(index);
  135 +
  136 + bool every(bool test(E element)) => _base.every(test);
  137 +
  138 + Iterable<T> expand<T>(Iterable<T> f(E element)) => _base.expand(f);
  139 +
  140 + E get first => _base.first;
  141 +
  142 + E firstWhere(bool test(E element), {E orElse()}) =>
  143 + _base.firstWhere(test, orElse: orElse);
  144 +
  145 + T fold<T>(T initialValue, T combine(T previousValue, E element)) =>
  146 + _base.fold(initialValue, combine);
  147 +
  148 + Iterable<E> followedBy(Iterable<E> other) => _base.followedBy(other);
  149 +
  150 + void forEach(void f(E element)) => _base.forEach(f);
  151 +
  152 + bool get isEmpty => _base.isEmpty;
  153 +
  154 + bool get isNotEmpty => _base.isNotEmpty;
  155 +
  156 + Iterator<E> get iterator => _base.iterator;
  157 +
  158 + String join([String separator = ""]) => _base.join(separator);
  159 +
  160 + E get last => _base.last;
  161 +
  162 + E lastWhere(bool test(E element), {E orElse()}) =>
  163 + _base.lastWhere(test, orElse: orElse);
  164 +
  165 + int get length => _base.length;
  166 +
  167 + Iterable<T> map<T>(T f(E element)) => _base.map(f);
  168 +
  169 + E reduce(E combine(E value, E element)) => _base.reduce(combine);
  170 +
  171 + @deprecated
  172 + Iterable<T> retype<T>() => cast<T>();
  173 +
  174 + E get single => _base.single;
  175 +
  176 + E singleWhere(bool test(E element), {E orElse()}) {
  177 + return _base.singleWhere(test, orElse: orElse);
  178 + }
  179 +
  180 + Iterable<E> skip(int n) => _base.skip(n);
  181 +
  182 + Iterable<E> skipWhile(bool test(E value)) => _base.skipWhile(test);
  183 +
  184 + Iterable<E> take(int n) => _base.take(n);
  185 +
  186 + Iterable<E> takeWhile(bool test(E value)) => _base.takeWhile(test);
  187 +
  188 + List<E> toList({bool growable = true}) => _base.toList(growable: growable);
  189 +
  190 + Set<E> toSet() => _base.toSet();
  191 +
  192 + Iterable<E> where(bool test(E element)) => _base.where(test);
  193 +
  194 + Iterable<T> whereType<T>() => _base.whereType<T>();
  195 +
  196 + String toString() => _base.toString();
  197 +}
@@ -32,6 +32,8 @@ class GetController extends State { @@ -32,6 +32,8 @@ class GetController extends State {
32 } 32 }
33 } 33 }
34 34
  35 + void close() {}
  36 +
35 @override 37 @override
36 Widget build(_) => throw ("build method can't be called"); 38 Widget build(_) => throw ("build method can't be called");
37 } 39 }
@@ -86,14 +88,24 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { @@ -86,14 +88,24 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
86 } 88 }
87 } else { 89 } else {
88 controller = widget.init; 90 controller = widget.init;
  91 + if (controller._allStates[controller] == null) {
  92 + controller._allStates[controller] = [];
  93 + }
89 controller._allStates[controller] 94 controller._allStates[controller]
90 .add(RealState(state: this, id: widget.id)); 95 .add(RealState(state: this, id: widget.id));
91 } 96 }
92 if (widget.initState != null) widget.initState(this); 97 if (widget.initState != null) widget.initState(this);
  98 + try {
  99 + controller?.initState();
  100 + } catch (e) {
  101 + if (Get.isLogEnable) print("Controller is not attach");
  102 + }
93 } 103 }
94 104
95 @override 105 @override
96 - void dispose() { 106 + void dispose() async {
  107 + super.dispose();
  108 +
97 if (widget.init != null) { 109 if (widget.init != null) {
98 var b = controller; 110 var b = controller;
99 if (b._allStates[controller].hashCode == this.hashCode) { 111 if (b._allStates[controller].hashCode == this.hashCode) {
@@ -109,6 +121,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { @@ -109,6 +121,7 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
109 121
110 if (widget.init != null) { 122 if (widget.init != null) {
111 if (widget.autoRemove && Get.isRegistred<T>()) { 123 if (widget.autoRemove && Get.isRegistred<T>()) {
  124 + controller.close();
112 Get.delete<T>(); 125 Get.delete<T>();
113 } 126 }
114 } else { 127 } else {
@@ -116,8 +129,6 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> { @@ -116,8 +129,6 @@ class _GetBuilderState<T extends GetController> extends State<GetBuilder<T>> {
116 controller._allStates[controller] 129 controller._allStates[controller]
117 .remove(RealState(state: this, id: widget.id)); 130 .remove(RealState(state: this, id: widget.id));
118 } 131 }
119 -  
120 - super.dispose();  
121 } 132 }
122 133
123 @override 134 @override
1 name: get 1 name: get
2 description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get. 2 description: Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
3 -version: 2.2.6 3 +version: 2.5.0
4 homepage: https://github.com/jonataslaw/get 4 homepage: https://github.com/jonataslaw/get
5 5
6 environment: 6 environment:
7 - sdk: ">=2.1.0 <3.0.0" 7 + sdk: ">=2.6.0 <3.0.0"
8 8
9 dependencies: 9 dependencies:
10 flutter: 10 flutter: