Jonny Borges
Committed by GitHub

Merge pull request #217 from Nipodemos/readme-reorganization

Readme reorganization
Showing 1 changed file with 469 additions and 406 deletions
1 ![](get.png) 1 ![](get.png)
2 -  
3 -*Languages: [English](README.md), [Brazilian Portuguese](README.pt-br.md).* 2 +
  3 +*Languages: English (this file), [Brazilian Portuguese](README.pt-br.md).*
4 4
5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get) 5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg) 6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
@@ -55,31 +55,48 @@ class Other extends StatelessWidget { @@ -55,31 +55,48 @@ class Other extends StatelessWidget {
55 55
56 This is a simple project but it already makes clear how powerful Get is. As your project grows, this difference will become more significant. Get was designed to work with teams, but it makes the job of an individual developer simple. Improve your deadlines, deliver everything on time without losing performance. Get is not for everyone, but if you identified with that phrase, Get is for you! 56 This is a simple project but it already makes clear how powerful Get is. As your project grows, this difference will become more significant. Get was designed to work with teams, but it makes the job of an individual developer simple. Improve your deadlines, deliver everything on time without losing performance. Get is not for everyone, but if you identified with that phrase, Get is for you!
57 57
58 -- [How to use?](#how-to-use)  
59 -- [Navigating without named routes](#navigating-without-named-routes)  
60 - - [SnackBars](#snackbars)  
61 - - [Dialogs](#dialogs)  
62 - - [BottomSheets](#bottomsheets)  
63 -- [Simple State Manager](#simple-state-manager)  
64 - - [Simple state manager usage](#simple-state-manager-usage)  
65 - - [No StatefulWidget:](#no-statefulwidget)  
66 - - [Forms of use:](#forms-of-use)  
67 -- [Reactive State Manager](#reactive-state-manager)  
68 - - [GetX vs GetBuilder vs Obx vs MixinBuilder](#getx-vs-getbuilder-vs-obx-vs-mixinbuilder)  
69 -- [Simple Instance Manager](#simple-instance-manager)  
70 -- [Bindings](#bindings)  
71 - - [To use this API you only need:](#to-use-this-api-you-only-need)  
72 -- [Workers:](#workers)  
73 -- [Navigate with named routes:](#navigate-with-named-routes)  
74 - - [Send data to named Routes:](#send-data-to-named-routes) 58 +- [Route Management](#route-management)
  59 + - [How to use?](#how-to-use)
  60 + - [Navigation without named routes](#navigation-without-named-routes)
  61 + - [Navigation with named routes](#navigation-with-named-routes)
  62 + - [Send data to named Routes:](#send-data-to-named-routes)
75 - [Dynamic urls links](#dynamic-urls-links) 63 - [Dynamic urls links](#dynamic-urls-links)
76 - [Middleware](#middleware) 64 - [Middleware](#middleware)
  65 + - [Navigation without context](#navigation-without-context)
  66 + - [SnackBars](#snackbars)
  67 + - [Dialogs](#dialogs)
  68 + - [BottomSheets](#bottomsheets)
  69 + - [Nested Navigation](#nested-navigation)
  70 +- [State Management](#state-management)
  71 + - [Simple State Manager](#simple-state-manager)
  72 + - [Advantages](#advantages)
  73 + - [Usage](#usage)
  74 + - [How it handles controllers](#how-it-handles-controllers)
  75 + - [You won't need StatefulWidgets anymore](#you-wont-need-statefulwidgets-anymore)
  76 + - [Why it exists](#why-it-exists)
  77 + - [Other ways of using it](#other-ways-of-using-it)
  78 + - [Unique IDs](#unique-ids)
  79 + - [Reactive State Manager](#reactive-state-manager)
  80 + - [Advantages](#advantages-1)
  81 + - [Usage](#usage-1)
  82 + - [Where .obs can be used](#where-obs-can-be-used)
  83 + - [Note about Lists](#note-about-lists)
  84 + - [Why i have to use .value?](#why-i-have-to-use-value)
  85 + - [Obx()](#obx)
  86 + - [Workers:](#workers)
  87 + - [Mixing the two state managers](#mixing-the-two-state-managers)
  88 + - [GetBuilder vs GetX && Obx vs MixinBuilder](#getbuilder-vs-getx--obx-vs-mixinbuilder)
  89 +- [Dependency Management](#dependency-management)
  90 + - [Simple Instance Manager](#simple-instance-manager)
  91 + - [Bindings](#bindings)
  92 + - [How to use](#how-to-use-1)
  93 + - [SmartManagement](#smartmanagement)
  94 +- [Utils](#utils)
77 - [Change Theme](#change-theme) 95 - [Change Theme](#change-theme)
78 - - [Optional Global Settings](#optional-global-settings)  
79 - - [Nested Navigators](#nested-navigators)  
80 - [Other Advanced APIs and Manual configurations](#other-advanced-apis-and-manual-configurations) 96 - [Other Advanced APIs and Manual configurations](#other-advanced-apis-and-manual-configurations)
  97 + - [Optional Global Settings](#optional-global-settings)
81 98
82 -#### Want to contribute to the project? We will be proud to highlight you as one of our collaborators. Here are some points where you can contribute and make Get (and Flutter) even better. 99 +*Want to contribute to the project? We will be proud to highlight you as one of our collaborators. Here are some points where you can contribute and make Get (and Flutter) even better.*
83 100
84 - Helping to translate the readme into other languages. 101 - Helping to translate the readme into other languages.
85 - Adding documentation to the readme (not even half of Get's functions have been documented yet). 102 - Adding documentation to the readme (not even half of Get's functions have been documented yet).
@@ -87,14 +104,12 @@ This is a simple project but it already makes clear how powerful Get is. As your @@ -87,14 +104,12 @@ This is a simple project but it already makes clear how powerful Get is. As your
87 - Offering PRs for code/tests. 104 - Offering PRs for code/tests.
88 - Including new functions. 105 - Including new functions.
89 106
  107 +# Route Management
  108 +
90 Any contribution is welcome! 109 Any contribution is welcome!
91 110
92 ## How to use? 111 ## How to use?
93 112
94 -<!-- - Flutter Master/Dev/Beta: version 2.0.x-dev  
95 -- Flutter Stable branch: version 2.0.x  
96 -(look for latest version on pub.dev) -->  
97 -  
98 Add this to your pubspec.yaml file: 113 Add this to your pubspec.yaml file:
99 114
100 ``` 115 ```
@@ -108,7 +123,8 @@ GetMaterialApp( // Before: MaterialApp( @@ -108,7 +123,8 @@ GetMaterialApp( // Before: MaterialApp(
108 home: MyHome(), 123 home: MyHome(),
109 ) 124 )
110 ``` 125 ```
111 -## Navigating without named routes 126 +
  127 +## Navigation without named routes
112 To navigate to a new screen: 128 To navigate to a new screen:
113 129
114 ```dart 130 ```dart
@@ -180,6 +196,220 @@ Get.to(HomePage()); @@ -180,6 +196,220 @@ Get.to(HomePage());
180 196
181 ``` 197 ```
182 198
  199 +## Navigation with named routes
  200 +- If you prefer to navigate by namedRoutes, Get also supports this.
  201 +
  202 +To navigate to nextScreen
  203 +```dart
  204 +Get.toNamed("/NextScreen");
  205 +```
  206 +To navigate and remove the previous screen from the tree.
  207 +```dart
  208 +Get.offNamed("/NextScreen");
  209 +```
  210 +To navigate and remove all previous screens from the tree.
  211 +```dart
  212 +Get.offAllNamed("/NextScreen");
  213 +```
  214 +
  215 +To define routes, use GetMaterialApp:
  216 +
  217 +```dart
  218 +void main() {
  219 + runApp(
  220 + GetMaterialApp(
  221 + initialRoute: '/',
  222 + namedRoutes: {
  223 + '/': GetRoute(page: MyHomePage()),
  224 + '/second': GetRoute(page: Second()),
  225 + '/third': GetRoute(page: Third(),transition: Transition.cupertino);
  226 + },
  227 + )
  228 + );
  229 +}
  230 +```
  231 +
  232 +### Send data to named Routes:
  233 +
  234 +Just send what you want for arguments. Get accepts anything here, whether it is a String, a Map, a List, or even a class instance.
  235 +```dart
  236 +Get.toNamed("/NextScreen", arguments: 'Get is the best');
  237 +```
  238 +on your class or controller:
  239 +
  240 +```dart
  241 +print(Get.arguments);
  242 +//print out: Get is the best
  243 +```
  244 +
  245 +### Dynamic urls links
  246 +Get offer advanced dynamic urls just like on the Web. Web developers have probably already wanted this feature on Flutter, and most likely have seen a package promise this feature and deliver a totally different syntax than a URL would have on web, but Get also solves that.
  247 +
  248 +```dart
  249 +Get.offAllNamed("/NextScreen?device=phone&id=354&name=Enzo");
  250 +```
  251 +on your controller/bloc/stateful/stateless class:
  252 +
  253 +```dart
  254 +print(Get.parameters['id']);
  255 +// out: 354
  256 +print(Get.parameters['name']);
  257 +// out: Enzo
  258 +```
  259 +
  260 +You can also receive NamedParameters with Get easily:
  261 +
  262 +```dart
  263 +void main() {
  264 + runApp(
  265 + GetMaterialApp(
  266 + initialRoute: '/',
  267 + namedRoutes: {
  268 + '/': GetRoute(page: MyHomePage()),
  269 + /// Important! :user is not a new route, it is just a parameter
  270 + /// specification. Do not use '/second/:user' and '/second'
  271 + /// if you need new route to user, use '/second/user/:user'
  272 + /// if '/second' is a route.
  273 + '/second/:user': GetRoute(page: Second()), // receive ID
  274 + '/third': GetRoute(page: Third(),transition: Transition.cupertino);
  275 + },
  276 + )
  277 + );
  278 +}
  279 +```
  280 +Send data on route name
  281 +```dart
  282 +Get.toNamed("/second/34954");
  283 +```
  284 +
  285 +On second screen take the data by parameter
  286 +
  287 +```dart
  288 +print(Get.parameters['user']);
  289 +// out: 34954
  290 +```
  291 +
  292 +And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (you can call your routes directly from your BLoC or Controller class), and when your app is compiled to the web, your routes will appear in the url <3
  293 +
  294 +
  295 +### Middleware
  296 +If you want listen Get events to trigger actions, you can to use routingCallback to it
  297 +```dart
  298 +GetMaterialApp(
  299 + routingCallback: (route) {
  300 + if(routing.current == '/second'){
  301 + openAds();
  302 + }
  303 + }
  304 +)
  305 +```
  306 +If you are not using GetMaterialApp, you can use the manual API to attach Middleware observer.
  307 +
  308 +```dart
  309 +void main() {
  310 + runApp(
  311 + MaterialApp(
  312 + onGenerateRoute: Router.generateRoute,
  313 + initialRoute: "/",
  314 + navigatorKey: Get.key,
  315 + navigatorObservers: [
  316 + GetObserver(MiddleWare.observer), // HERE !!!
  317 + ],
  318 + ),
  319 + );
  320 +}
  321 +```
  322 +Create a MiddleWare class
  323 +
  324 +```dart
  325 +class MiddleWare {
  326 + static observer(Routing routing) {
  327 + /// You can listen in addition to the routes, the snackbars, dialogs and bottomsheets on each screen.
  328 + ///If you need to enter any of these 3 events directly here,
  329 + ///you must specify that the event is != Than you are trying to do.
  330 + if (routing.current == '/second' && !routing.isSnackbar) {
  331 + Get.snackbar("Hi", "You are on second route");
  332 + } else if (routing.current =='/third'){
  333 + print('last route called');
  334 + }
  335 + }
  336 +}
  337 +```
  338 +
  339 +Now, use Get on your code:
  340 +
  341 +```dart
  342 +class First extends StatelessWidget {
  343 + @override
  344 + Widget build(BuildContext context) {
  345 + return Scaffold(
  346 + appBar: AppBar(
  347 + leading: IconButton(
  348 + icon: Icon(Icons.add),
  349 + onPressed: () {
  350 + Get.snackbar("hi", "i am a modern snackbar");
  351 + },
  352 + ),
  353 + title: Text('First Route'),
  354 + ),
  355 + body: Center(
  356 + child: RaisedButton(
  357 + child: Text('Open route'),
  358 + onPressed: () {
  359 + Get.toNamed("/second");
  360 + },
  361 + ),
  362 + ),
  363 + );
  364 + }
  365 +}
  366 +
  367 +class Second extends StatelessWidget {
  368 + @override
  369 + Widget build(BuildContext context) {
  370 + return Scaffold(
  371 + appBar: AppBar(
  372 + leading: IconButton(
  373 + icon: Icon(Icons.add),
  374 + onPressed: () {
  375 + Get.snackbar("hi", "i am a modern snackbar");
  376 + },
  377 + ),
  378 + title: Text('second Route'),
  379 + ),
  380 + body: Center(
  381 + child: RaisedButton(
  382 + child: Text('Open route'),
  383 + onPressed: () {
  384 + Get.toNamed("/third");
  385 + },
  386 + ),
  387 + ),
  388 + );
  389 + }
  390 +}
  391 +
  392 +class Third extends StatelessWidget {
  393 + @override
  394 + Widget build(BuildContext context) {
  395 + return Scaffold(
  396 + appBar: AppBar(
  397 + title: Text("Third Route"),
  398 + ),
  399 + body: Center(
  400 + child: RaisedButton(
  401 + onPressed: () {
  402 + Get.back();
  403 + },
  404 + child: Text('Go back!'),
  405 + ),
  406 + ),
  407 + );
  408 + }
  409 +}
  410 +```
  411 +## Navigation without context
  412 +
183 ### SnackBars 413 ### SnackBars
184 414
185 To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold, 415 To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold,
@@ -302,63 +532,118 @@ Get.bottomSheet( @@ -302,63 +532,118 @@ Get.bottomSheet(
302 ); 532 );
303 ``` 533 ```
304 534
305 -## Simple State Manager  
306 -There are currently several state managers for Flutter. However, most of them involve using ChangeNotifier to update widgets and this is a bad and very bad approach to performance of medium or large applications. You can check in the official Flutter documentation that ChangeNotifier should be used with 1 or a maximum of 2 listeners (https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html), making it practically unusable for any application medium or large. Other state managers are good, but have their nuances. BLoC is very safe and efficient, but it is very complex for beginners, which has kept people from developing with Flutter. MobX is easier than BLoC and reactive, almost perfect, I would say, but you need to use a code generator that for large applications, reduces productivity, you will need to drink a lot of coffees until your code is ready again after a Flutter clean (And this is not MobX's fault, but the codegen which is really slow!). Provider uses InheritedWidget to deliver the same listener, as a way of solving the problem reported above with ChangeNotifier, which implies that any access to its ChangeNotifier class must be within the widget tree because of the context to access o Inherited.  
307 -  
308 -Get isn't better or worse than any other state manager, but that you should analyze these points as well as the points below to choose between using Get in pure form (Vanilla), or using it in conjunction with another state manager. Definitely, Get is not the enemy of any other state manager, because Get is a microframework, not just a state manager, and can be used either alone or in conjunction with them.  
309 -  
310 -Get has a state manager that is extremely light and easy (written in just 95 lines of code), which does not use ChangeNotifier, will meet the need especially for those new to Flutter, and will not cause problems for large applications.  
311 -  
312 -What performance improvements does Get bring?  
313 -  
314 -1- Update only the required widget.  
315 -  
316 -2- Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb for until).  
317 -  
318 -3- Forget StatefulWidget! With Get you will never need it. 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.  
319 -  
320 -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.  
321 -  
322 -5- Do you need to trigger an event to update a widget as soon as it is rendered? GetBuilder has the property "initState", just like StatefulWidget, and you can call events from your controller, directly from it, no more events being placed in your initState.  
323 535
324 -6- Do you need to trigger an action like closing streams, timers and etc? GetBuilder also has the dispose property, where you can call events as soon as that widget is destroyed. 536 +## Nested Navigation
325 537
326 -7- Use streams only if necessary. You can use your StreamControllers inside your controller normally, and use StreamBuilder also normally, but remember, a stream reasonably consumes memory, reactive programming is beautiful, but you shouldn't abuse it. 30 streams open simultaneously can be worse than changeNotifier (and changeNotifier is very bad).  
327 -  
328 -8- Update widgets without spending ram for that. Get stores only the GetBuilder creator ID, and updates that GetBuilder when necessary. The memory consumption of the get ID storage in memory is very low even for thousands of GetBuilders. When you create a new GetBuilder, you are actually sharing the state of GetBuilder that has a creator ID. A new state is not created for each GetBuilder, which saves A LOT OF ram for large applications. Basically your application will be entirely Stateless, and the few Widgets that will be Stateful (within GetBuilder) will have a single state, and therefore updating one will update them all. The state is just one.  
329 -  
330 -9- Get is omniscient and in most cases it knows exactly the time to take a controller out of memory. You should not worry about when to dispose of a controller, Get knows the best time to do this. Example:  
331 -  
332 -- Class a => Class B (has controller X) => Class C (has controller X)  
333 -  
334 -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. 538 +Get made Flutter's nested navigation even easier.
  539 +You don't need the context, and you will find your navigation stack by Id.
335 540
336 -### Simple state manager usage 541 +- NOTE: Creating parallel navigation stacks can be dangerous. The ideal is not to use NestedNavigators, or to use sparingly. If your project requires it, go ahead, but keep in mind that keeping multiple navigation stacks in memory may not be a good idea for RAM consumption.
337 542
  543 +See how simple it is:
338 ```dart 544 ```dart
339 -// Create controller class and extends GetController  
340 -class Controller extends GetController {  
341 - int counter = 0;  
342 - void increment() {  
343 - counter++;  
344 - update(); // use update() to update counter variable on UI when increment be called  
345 - }  
346 -}  
347 -// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called  
348 -GetBuilder<Controller>(  
349 - init: Controller(), // INIT IT ONLY THE FIRST TIME  
350 - builder: (_) => Text(  
351 - '${_.counter}',  
352 - ),  
353 -)  
354 -//Initialize your controller only the first time. The second time you are using ReBuilder for the same controller, do not use it again. Your controller will be automatically removed from memory as soon as the widget that marked it as 'init' is deployed. You don't have to worry about that, Get will do it automatically, just make sure you don't start the same controller twice.  
355 -```  
356 -**Done!**  
357 -- You have already learned how to manage states with Get.  
358 -  
359 -- Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Bindings class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works.  
360 -  
361 - 545 +Navigator(
  546 + key: Get.nestedKey(1), // create a key by index
  547 + initialRoute: '/',
  548 + onGenerateRoute: (settings) {
  549 + if (settings.name == '/') {
  550 + return GetRouteBase(
  551 + page: Scaffold(
  552 + appBar: AppBar(
  553 + title: Text("Main"),
  554 + ),
  555 + body: Center(
  556 + child: FlatButton(
  557 + color: Colors.blue,
  558 + onPressed: () {
  559 + Get.toNamed('/second', id:1); // navigate by your nested route by index
  560 + },
  561 + child: Text("Go to second"),
  562 + ),
  563 + ),
  564 + ),
  565 + );
  566 + } else if (settings.name == '/second') {
  567 + return GetRouteBase(
  568 + page: Center(
  569 + child: Scaffold(
  570 + appBar: AppBar(
  571 + title: Text("Main"),
  572 + ),
  573 + body: Center(
  574 + child: Text("second")
  575 + ),
  576 + ),
  577 + ),
  578 + );
  579 + }
  580 + }
  581 +),
  582 +```
  583 +
  584 +
  585 +# State Management
  586 +
  587 +There are currently several state managers for Flutter. However, most of them involve using ChangeNotifier to update widgets and this is a bad and very bad approach to performance of medium or large applications. You can check in the official Flutter documentation that [ChangeNotifier should be used with 1 or a maximum of 2 listeners](https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html), making it practically unusable for any application medium or large.
  588 +
  589 +Other state managers are good, but have their nuances:
  590 +- BLoC is very safe and efficient, but it is very complex for beginners, which has kept people from developing with Flutter.
  591 +- MobX is easier than BLoC and reactive, almost perfect, I would say, but you need to use a code generator, that for large applications, reduces productivity, since you will need to drink a lot of coffees until your code is ready again after a `flutter clean` (And this is not MobX's fault, but the codegen which is really slow!).
  592 +- Provider uses InheritedWidget to deliver the same listener, as a way of solving the problem reported above with ChangeNotifier, which implies that any access to its ChangeNotifier class must be within the widget tree because of the context to access o Inherited.
  593 +
  594 +
  595 +Get isn't better or worse than any other state manager, but that you should analyze these points as well as the points below to choose between using Get in pure form (Vanilla), or using it in conjunction with another state manager. Definitely, Get is not the enemy of any other state manager, because Get is a microframework, not just a state manager, and can be used either alone or in conjunction with them.
  596 +
  597 +## Simple State Manager
  598 +
  599 +Get has a state manager that is extremely light and easy, which does not use ChangeNotifier, will meet the need especially for those new to Flutter, and will not cause problems for large applications.
  600 +
  601 +### Advantages
  602 +
  603 +1. Update only the required widgets.
  604 +
  605 +2. Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb).
  606 +
  607 +3. Forget StatefulWidget! With Get you will never need it. 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.
  608 +
  609 +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.
  610 +
  611 +5. Do you need to trigger an event to update a widget as soon as it is rendered? GetBuilder has the property "initState", just like StatefulWidget, and you can call events from your controller, directly from it, no more events being placed in your initState.
  612 +
  613 +6. Do you need to trigger an action like closing streams, timers and etc? GetBuilder also has the dispose property, where you can call events as soon as that widget is destroyed.
  614 +
  615 +7. Use streams only if necessary. You can use your StreamControllers inside your controller normally, and use StreamBuilder also normally, but remember, a stream reasonably consumes memory, reactive programming is beautiful, but you shouldn't abuse it. 30 streams open simultaneously can be worse than changeNotifier (and changeNotifier is very bad).
  616 +
  617 +8. Update widgets without spending ram for that. Get stores only the GetBuilder creator ID, and updates that GetBuilder when necessary. The memory consumption of the get ID storage in memory is very low even for thousands of GetBuilders. When you create a new GetBuilder, you are actually sharing the state of GetBuilder that has a creator ID. A new state is not created for each GetBuilder, which saves A LOT OF ram for large applications. Basically your application will be entirely Stateless, and the few Widgets that will be Stateful (within GetBuilder) will have a single state, and therefore updating one will update them all. The state is just one.
  618 +
  619 +9. Get is omniscient and in most cases it knows exactly the time to take a controller out of memory. You should not worry about when to dispose of a controller, Get knows the best time to do this.
  620 +
  621 +### Usage
  622 +
  623 +```dart
  624 +// Create controller class and extends GetController
  625 +class Controller extends GetController {
  626 + int counter = 0;
  627 + void increment() {
  628 + counter++;
  629 + update(); // use update() to update counter variable on UI when increment be called
  630 + }
  631 +}
  632 +// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called
  633 +GetBuilder<Controller>(
  634 + init: Controller(), // INIT IT ONLY THE FIRST TIME
  635 + builder: (_) => Text(
  636 + '${_.counter}',
  637 + ),
  638 +)
  639 +//Initialize your controller only the first time. The second time you are using ReBuilder for the same controller, do not use it again. Your controller will be automatically removed from memory as soon as the widget that marked it as 'init' is deployed. You don't have to worry about that, Get will do it automatically, just make sure you don't start the same controller twice.
  640 +```
  641 +**Done!**
  642 +- You have already learned how to manage states with Get.
  643 +
  644 +- Note: You may want a larger organization, and not use the init property. For that, you can create a class and extends Bindings class, and within it mention the controllers that will be created within that route. Controllers will not be created at that time, on the contrary, this is just a statement, so that the first time you use a Controller, Get will know where to look. Get will remain lazyLoad, and will continue to dispose Controllers when they are no longer needed. See the pub.dev example to see how it works.
  645 +
  646 +
362 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): 647 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):
363 648
364 ```dart 649 ```dart
@@ -404,7 +689,14 @@ FloatingActionButton( @@ -404,7 +689,14 @@ FloatingActionButton(
404 ``` 689 ```
405 When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically. 690 When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically.
406 691
407 -#### No StatefulWidget: 692 +### How it handles controllers
  693 +Let's say we have this:
  694 +
  695 +`Class a => Class B (has controller X) => Class C (has controller X)`
  696 +
  697 +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.
  698 +
  699 +### You won't need StatefulWidgets anymore
408 Using StatefulWidgets means storing the state of entire screens unnecessarily, even because if you need to minimally rebuild a widget, you will embed it in a Consumer/Observer/BlocProvider/GetBuilder/GetX/Obx, which will be another StatefulWidget. 700 Using StatefulWidgets means storing the state of entire screens unnecessarily, even because if you need to minimally rebuild a widget, you will embed it in a Consumer/Observer/BlocProvider/GetBuilder/GetX/Obx, which will be another StatefulWidget.
409 The StatefulWidget class is a class larger than StatelessWidget, which will allocate more RAM, and this may not make a significant difference between one or two classes, but it will most certainly do when you have 100 of them! 701 The StatefulWidget class is a class larger than StatelessWidget, which will allocate more RAM, and this may not make a significant difference between one or two classes, but it will most certainly do when you have 100 of them!
410 Unless you need to use a mixin, like TickerProviderStateMixin, it will be totally unnecessary to use a StatefulWidget with Get. 702 Unless you need to use a mixin, like TickerProviderStateMixin, it will be totally unnecessary to use a StatefulWidget with Get.
@@ -431,6 +723,8 @@ void onInit() { @@ -431,6 +723,8 @@ void onInit() {
431 ``` 723 ```
432 724
433 - NOTE: If you want to start a method at the moment the controller is called for the first time, you DON'T NEED to use constructors for this, in fact, using a performance-oriented package like Get, this borders on bad practice, because it deviates from the logic in which the controllers are created or allocated (if you create an instance of this controller, the constructor will be called immediately, you will be populating a controller before it is even used, you are allocating memory without it being in use, this definitely hurts the principles of this library). The onInit() methods; and onClose(); were created for this, they will be called when the Controller is created, or used for the first time, depending on whether you are using Get.lazyPut or not. If you want, for example, to make a call to your API to populate data, you can forget about the old-fashioned method of initState/dispose, just start your call to the api in onInit, and if you need to execute any command like closing streams, use the onClose() for that. 725 - NOTE: If you want to start a method at the moment the controller is called for the first time, you DON'T NEED to use constructors for this, in fact, using a performance-oriented package like Get, this borders on bad practice, because it deviates from the logic in which the controllers are created or allocated (if you create an instance of this controller, the constructor will be called immediately, you will be populating a controller before it is even used, you are allocating memory without it being in use, this definitely hurts the principles of this library). The onInit() methods; and onClose(); were created for this, they will be called when the Controller is created, or used for the first time, depending on whether you are using Get.lazyPut or not. If you want, for example, to make a call to your API to populate data, you can forget about the old-fashioned method of initState/dispose, just start your call to the api in onInit, and if you need to execute any command like closing streams, use the onClose() for that.
  726 +
  727 +### Why it exists
434 The purpose of this package is precisely to give you a complete solution for navigation of routes, management of dependencies and states, using the least possible dependencies, with a high degree of decoupling. Get engages all high and low level Flutter APIs within itself, to ensure that you work with the least possible coupling. We centralize everything in a single package, to ensure that you don't have any kind of coupling in your project. That way, you can put only widgets in your view, and leave the part of your team that works with the business logic free, to work with the business logic without depending on any element of the View. This provides a much cleaner working environment, so that part of your team works only with widgets, without worrying about sending data to your controller, and part of your team works only with the business logic in its breadth, without depending on no element of the view. 728 The purpose of this package is precisely to give you a complete solution for navigation of routes, management of dependencies and states, using the least possible dependencies, with a high degree of decoupling. Get engages all high and low level Flutter APIs within itself, to ensure that you work with the least possible coupling. We centralize everything in a single package, to ensure that you don't have any kind of coupling in your project. That way, you can put only widgets in your view, and leave the part of your team that works with the business logic free, to work with the business logic without depending on any element of the View. This provides a much cleaner working environment, so that part of your team works only with widgets, without worrying about sending data to your controller, and part of your team works only with the business logic in its breadth, without depending on no element of the view.
435 729
436 So to simplify this: 730 So to simplify this:
@@ -458,7 +752,7 @@ Controller life cycle: @@ -458,7 +752,7 @@ Controller life cycle:
458 - onClose() where it is closed to make any changes in preparation for the delete method 752 - onClose() where it is closed to make any changes in preparation for the delete method
459 - deleted: you do not have access to this API because it is literally removing the controller from memory. It is literally deleted, without leaving any trace. 753 - deleted: you do not have access to this API because it is literally removing the controller from memory. It is literally deleted, without leaving any trace.
460 754
461 -##### Forms of use: 755 +### Other ways of using it
462 756
463 You can use Controller instance directly on GetBuilder value: 757 You can use Controller instance directly on GetBuilder value:
464 758
@@ -513,9 +807,8 @@ GetBuilder<Controller>( @@ -513,9 +807,8 @@ GetBuilder<Controller>(
513 ), 807 ),
514 808
515 ``` 809 ```
516 -<!-- This approach is not recommended, as you will have to manually dispose of your controllers, close your streams manually, and literally give up one of the great benefits of this library, which is intelligent memory control. But if you trust your potential, go ahead! -->  
517 -  
518 810
  811 +### Unique IDs
519 If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs: 812 If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs:
520 ```dart 813 ```dart
521 GetBuilder<Controller>( 814 GetBuilder<Controller>(
@@ -537,22 +830,25 @@ update(['text'], counter < 10); @@ -537,22 +830,25 @@ update(['text'], counter < 10);
537 ``` 830 ```
538 831
539 GetX does this automatically and only reconstructs the widget that uses the exact variable that was changed, if you change a variable to the same as the previous one and that does not imply a change of state , GetX will not rebuild the widget to save memory and CPU cycles (3 is being displayed on the screen, and you change the variable to 3 again. In most state managers, this will cause a new rebuild, but with GetX the widget will only is rebuilt again, if in fact his state has changed). 832 GetX does this automatically and only reconstructs the widget that uses the exact variable that was changed, if you change a variable to the same as the previous one and that does not imply a change of state , GetX will not rebuild the widget to save memory and CPU cycles (3 is being displayed on the screen, and you change the variable to 3 again. In most state managers, this will cause a new rebuild, but with GetX the widget will only is rebuilt again, if in fact his state has changed).
  833 +
  834 +## Reactive State Manager
  835 +
  836 +### Advantages
540 GetBuilder is aimed precisely at multiple state control. Imagine that you added 30 products to a cart, you click delete one, at the same time that the list is updated, the price is updated and the badge in the shopping cart is updated to a smaller number. This type of approach makes GetBuilder killer, because it groups states and changes them all at once without any "computational logic" for that. GetBuilder was created with this type of situation in mind, since for ephemeral change of state, you can use setState and you would not need a state manager for this. However, there are situations where you want only the widget where a certain variable has been changed to be rebuilt, and this is what GetX does with a mastery never seen before. 837 GetBuilder is aimed precisely at multiple state control. Imagine that you added 30 products to a cart, you click delete one, at the same time that the list is updated, the price is updated and the badge in the shopping cart is updated to a smaller number. This type of approach makes GetBuilder killer, because it groups states and changes them all at once without any "computational logic" for that. GetBuilder was created with this type of situation in mind, since for ephemeral change of state, you can use setState and you would not need a state manager for this. However, there are situations where you want only the widget where a certain variable has been changed to be rebuilt, and this is what GetX does with a mastery never seen before.
541 838
542 That way, if you want an individual controller, you can assign IDs for that, or use GetX. This is up to you, remembering that the more "individual" widgets you have, the more the performance of GetX will stand out, while the performance of GetBuilder should be superior, when there is multiple change of state. 839 That way, if you want an individual controller, you can assign IDs for that, or use GetX. This is up to you, remembering that the more "individual" widgets you have, the more the performance of GetX will stand out, while the performance of GetBuilder should be superior, when there is multiple change of state.
543 840
544 -You can use both in any situation, but if you want to tune their application to the maximum possible performance, I would say that: if your variables are changed at different times, use GetX, because there is no competition for it when the subject is to rebuild only what is necessary, if you do not need unique IDs, because all your variables will be changed when you perform an action, use GetBuilder, because it is a simple state updater in blocks, made in a few lines of code, to make just what he promises to do: update state in blocks. There is no way to compare RAM, CPU, or anything else from a giant state manager to a simple StatefulWidget (like GetBuilder) that is updated when you call update(this). It was done in a simple way, to have the least computational logic involved, just to fulfill a single purpose and spend the minimum resources possible for that purpose. 841 +You can use both in any situation, but if you want to tune their application to the maximum possible performance, I would say that: if your variables are changed at different times, use GetX, because there is no competition for it when the subject is to rebuild only what is necessary, if you do not need unique IDs, because all your variables will be changed when you perform an action, use GetBuilder, because it is a simple state updater in blocks, made in a few lines of code, to make just what he promises to do: update state in blocks. There is no way to compare RAM, CPU, or anything else from a giant state manager to a simple StatefulWidget (like GetBuilder) that is updated when you call update(). It was done in a simple way, to have the least computational logic involved, just to fulfill a single purpose and spend the minimum resources possible for that purpose.
545 If you want a powerful state manager, you can go without fear to GetX. It does not work with variables, but flows, everything in it is streams under the hood. You can use rxDart in conjunction with it, because everything is stream, you can hear the event of each "variable", because everything in it is stream, it is literally BLoC, easier than MobX, and without code generator or decorations . 842 If you want a powerful state manager, you can go without fear to GetX. It does not work with variables, but flows, everything in it is streams under the hood. You can use rxDart in conjunction with it, because everything is stream, you can hear the event of each "variable", because everything in it is stream, it is literally BLoC, easier than MobX, and without code generator or decorations .
546 843
547 -  
548 -## Reactive State Manager  
549 -  
550 If you want power, Get gives you the most advanced state manager you could ever have. 844 If you want power, Get gives you the most advanced state manager you could ever have.
551 GetX was built 100% based on Streams, and give you all the firepower that BLoC gave you, with an easier facility than using MobX. 845 GetX was built 100% based on Streams, and give you all the firepower that BLoC gave you, with an easier facility than using MobX.
552 Without decorations, you can turn anything into Observable with just a ".obs". 846 Without decorations, you can turn anything into Observable with just a ".obs".
553 847
554 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. 848 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.
555 -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: 849 +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.
  850 +
  851 +### Usage
556 852
557 ```dart 853 ```dart
558 final count1 = 0.obs; 854 final count1 = 0.obs;
@@ -609,6 +905,7 @@ ctl.count.value++ @@ -609,6 +905,7 @@ ctl.count.value++
609 905
610 You could update the counter variable in your UI, regardless of where it is stored. 906 You could update the counter variable in your UI, regardless of where it is stored.
611 907
  908 +### Where .obs can be used
612 You can transform anything on obs: 909 You can transform anything on obs:
613 910
614 ```dart 911 ```dart
@@ -648,6 +945,7 @@ Camila @@ -648,6 +945,7 @@ Camila
648 945
649 ``` 946 ```
650 947
  948 +### Note about Lists
651 Working with Lists using Get is the best and most enjoyable thing in the world. They are completely observable as are the objects within it. That way, if you add a value to a list, it will automatically rebuild the widgets that use it. 949 Working with Lists using Get is the best and most enjoyable thing in the world. They are completely observable as are the objects within it. That way, if you add a value to a list, it will automatically rebuild the widgets that use it.
652 You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that, unfortunate primitive types like String and int cannot be extended, making the use of .value mandatory, but that won't be a problem if you work with gets and setters for these. 950 You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that, unfortunate primitive types like String and int cannot be extended, making the use of .value mandatory, but that won't be a problem if you work with gets and setters for these.
653 951
@@ -665,29 +963,78 @@ You don't have to work with sets if you don't want to. you can use the "assign ' @@ -665,29 +963,78 @@ You don't have to work with sets if you don't want to. you can use the "assign '
665 The "assign" api will clear your list, and add a single object that you want to start there. 963 The "assign" api will clear your list, and add a single object that you want to start there.
666 The "assignAll" api will clear the existing list and add any iterable objects that you inject into it. 964 The "assignAll" api will clear the existing list and add any iterable objects that you inject into it.
667 965
  966 +### Why i have to use .value?
668 We could remove the obligation to use 'value' to String and int with a simple decoration and code generator, but the purpose of this lib is precisely not to need any external dependency. It is to offer an environment ready for programming, involving the essentials (management of routes, dependencies and states), in a simple, light and performance way without needing any external package. You can literally add 3 letters to your pubspec (get) and start programming. All solutions included by default, from route management to state management, aim at ease, productivity and performance. The total weight of this library is less than that of a single state manager, even though it is a complete solution, and that is what you must understand. If you are bothered by value, and like a code generator, MobX is a great alternative, and you can use it in conjunction with Get. For those who want to add a single dependency in pubspec and start programming without worrying about the version of a package being incompatible with another, or if the error of a state update is coming from the state manager or dependency, or still, do not want to worrying about the availability of controllers, whether literally "just programming", get is just perfect. 967 We could remove the obligation to use 'value' to String and int with a simple decoration and code generator, but the purpose of this lib is precisely not to need any external dependency. It is to offer an environment ready for programming, involving the essentials (management of routes, dependencies and states), in a simple, light and performance way without needing any external package. You can literally add 3 letters to your pubspec (get) and start programming. All solutions included by default, from route management to state management, aim at ease, productivity and performance. The total weight of this library is less than that of a single state manager, even though it is a complete solution, and that is what you must understand. If you are bothered by value, and like a code generator, MobX is a great alternative, and you can use it in conjunction with Get. For those who want to add a single dependency in pubspec and start programming without worrying about the version of a package being incompatible with another, or if the error of a state update is coming from the state manager or dependency, or still, do not want to worrying about the availability of controllers, whether literally "just programming", get is just perfect.
  968 +
669 If you have no problem with the MobX code generator, or have no problem with the BLoC boilerplate, you can simply use Get for routes, and forget that it has state manager. Get SEM and RSM were born out of necessity, my company had a project with more than 90 controllers, and the code generator simply took more than 30 minutes to complete its tasks after a Flutter Clean on a reasonably good machine, if your project it has 5, 10, 15 controllers, any state manager will supply you well. If you have an absurdly large project, and code generator is a problem for you, you have been awarded this solution. 969 If you have no problem with the MobX code generator, or have no problem with the BLoC boilerplate, you can simply use Get for routes, and forget that it has state manager. Get SEM and RSM were born out of necessity, my company had a project with more than 90 controllers, and the code generator simply took more than 30 minutes to complete its tasks after a Flutter Clean on a reasonably good machine, if your project it has 5, 10, 15 controllers, any state manager will supply you well. If you have an absurdly large project, and code generator is a problem for you, you have been awarded this solution.
670 970
671 Obviously, if someone wants to contribute to the project and create a code generator, or something similar, I will link in this readme as an alternative, my need is not the need for all devs, but for now I say, there are good solutions that already do that, like MobX. 971 Obviously, if someone wants to contribute to the project and create a code generator, or something similar, I will link in this readme as an alternative, my need is not the need for all devs, but for now I say, there are good solutions that already do that, like MobX.
672 972
  973 +### Obx()
  974 +
673 Typing in Get using Bindings is unnecessary. you can use the Obx widget instead of GetX which only receives the anonymous function that creates a widget. 975 Typing in Get using Bindings is unnecessary. you can use the Obx widget instead of GetX which only receives the anonymous function that creates a widget.
674 Obviously, if you don't use a type, you will need to have an instance of your controller to use the variables, or use `Get.find<Controller>()` .value or Controller.to.value to retrieve the value. 976 Obviously, if you don't use a type, you will need to have an instance of your controller to use the variables, or use `Get.find<Controller>()` .value or Controller.to.value to retrieve the value.
675 977
676 -### GetX vs GetBuilder vs Obx vs MixinBuilder 978 +### Workers:
  979 +Workers will assist you, triggering specific callbacks when an event occurs.
  980 +
  981 +
  982 +```dart
  983 +/// Called every time the variable $_ is changed
  984 +ever(count1, (_) => print("$_ has been changed"));
  985 +
  986 +/// Called only first time the variable $_ is changed
  987 +once(count1, (_) => print("$_ was changed once"));
  988 +
  989 +/// Anti DDos - Called every time the user stops typing for 1 second, for example.
  990 +debounce(count1, (_) => print("debouce$_"), time: Duration(seconds: 1));
  991 +
  992 +/// Ignore all changes within 1 second.
  993 +interval(count1, (_) => print("interval $_"), time: Duration(seconds: 1));
  994 +```
  995 +- ever
  996 +'ever' is called every time its variable is changed. That's it.
  997 +
  998 +- ever
  999 +'once' is called only the first time the variable has been changed.
  1000 +
  1001 +- debounce
  1002 +'debounce' is very useful in search functions, where you only want the API to be called when the user finishes typing. If the user types "Jonny", you will have 5 searches in the APIs, by the letter J, o, n, n, and y. With Get this does not happen, because you will have a "debounce" Worker that will only be triggered at the end of typing.
  1003 +
  1004 +- interval
  1005 +'interval' is different from the debouce. debouce if the user makes 1000 changes to a variable within 1 second, he will send only the last one after the stipulated timer (the default is 800 milliseconds). Interval will instead ignore all user actions for the stipulated period. If you send events for 1 minute, 1000 per second, debounce will only send you the last one, when the user stops strafing events. interval will deliver events every second, and if set to 3 seconds, it will deliver 20 events that minute. This is recommended to avoid abuse, in functions where the user can quickly click on something and get some advantage (imagine that the user can earn coins by clicking on something, if he clicked 300 times in the same minute, he would have 300 coins, using interval, you you can set a time frame for 3 seconds, and even then clicking 300 or a thousand times, the maximum he would get in 1 minute would be 20 coins, clicking 300 or 1 million times). The debounce is suitable for anti-DDos, for functions like search where each change to onChange would cause a query to your api. Debounce will wait for the user to stop typing the name, to make the request. If it were used in the coin scenario mentioned above, the user would only win 1 coin, because it is only executed, when the user "pauses" for the established time.
  1006 +
  1007 +
  1008 +## Mixing the two state managers
  1009 +Some people opened a feature request, as they wanted to use only one type of reactive variable, and the other mechanics, and needed to insert an Obx into a GetBuilder for this. Thinking about it MixinBuilder was created. It allows both reactive changes by changing ".obs" variables, and mechanical updates via update(). However, of the 4 widgets he is the one that consumes the most resources, since in addition to having a Subscription to receive change events from his children, he subscribes to the update method of his controller.
  1010 +
  1011 +- Note: To use GetBuilder and MixinBuilder you must use GetController. To use GetX and Obx you must use RxController.
  1012 +Probably using a GetController using GetX and Obx will work, but it will not be possible to use an RxController on a GetBuilder.
  1013 +Extending these controllers is important, as they have life cycles, and can "start" and "end" events in their onInit() and onClose() methods.
  1014 +
  1015 +## GetBuilder vs GetX && Obx vs MixinBuilder
677 In a decade working with programming I was able to learn some valuable lessons. 1016 In a decade working with programming I was able to learn some valuable lessons.
  1017 +
678 My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible. 1018 My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible.
679 However, it is not suitable for all situations. Often all you need is to change the state of 2 or 3 widgets at the same time, or an ephemeral change of state, in which case reactive programming is not bad, but it is not appropriate. 1019 However, it is not suitable for all situations. Often all you need is to change the state of 2 or 3 widgets at the same time, or an ephemeral change of state, in which case reactive programming is not bad, but it is not appropriate.
  1020 +
680 Reactive programming has a higher consumption of RAM consumption that can be compensated for by the individual workflow, which will ensure that only one widget is rebuilt and when necessary, but creating a list with 80 objects, each with several streams is not a good one idea. Open the dart inspect and check how much a StreamBuilder consumes, and you'll understand what I'm trying to tell you. 1021 Reactive programming has a higher consumption of RAM consumption that can be compensated for by the individual workflow, which will ensure that only one widget is rebuilt and when necessary, but creating a list with 80 objects, each with several streams is not a good one idea. Open the dart inspect and check how much a StreamBuilder consumes, and you'll understand what I'm trying to tell you.
  1022 +
681 With that in mind, I created the simple state manager. It is simple, and that is exactly what you should demand from it: updating state in blocks in a simple way, and in the most economical way. 1023 With that in mind, I created the simple state manager. It is simple, and that is exactly what you should demand from it: updating state in blocks in a simple way, and in the most economical way.
  1024 +
682 GetBuilder is very economical in RAM, and there is hardly a more economical approach than him (at least I can't imagine one, if it exists, please let us know). 1025 GetBuilder is very economical in RAM, and there is hardly a more economical approach than him (at least I can't imagine one, if it exists, please let us know).
  1026 +
683 However, GetBuilder is still a mechanical state manager, you need to call update() just like you would need to call Provider's notifyListeners(). 1027 However, GetBuilder is still a mechanical state manager, you need to call update() just like you would need to call Provider's notifyListeners().
  1028 +
684 There are other situations where reactive programming is really interesting, and not working with it is the same as reinventing the wheel. With that in mind, GetX was created to provide everything that is most modern and advanced in a state manager. It updates only what is necessary and when necessary, if you have an error and send 300 state changes simultaneously, GetX will filter and update the screen only if the state actually changes. 1029 There are other situations where reactive programming is really interesting, and not working with it is the same as reinventing the wheel. With that in mind, GetX was created to provide everything that is most modern and advanced in a state manager. It updates only what is necessary and when necessary, if you have an error and send 300 state changes simultaneously, GetX will filter and update the screen only if the state actually changes.
  1030 +
685 GetX is still more economical than any other reactive state manager, but it consumes a little more RAM than GetBuilder. Thinking about it and aiming to maximize the consumption of resources that Obx was created. Unlike GetX and GetBuilder, you will not be able to initialize a controller inside an Obx, it is just a Widget with a StreamSubscription that receives change events from your children, that's all. It is more economical than GetX, but loses to GetBuilder, which was to be expected, since it is reactive, and GetBuilder has the most simplistic approach that exists, of storing a widget's hashcode and its StateSetter. With Obx you don't need to write your controller type, and you can hear the change from multiple different controllers, but it needs to be initialized before, either using the example approach at the beginning of this readme, or using the Bindings class. 1031 GetX is still more economical than any other reactive state manager, but it consumes a little more RAM than GetBuilder. Thinking about it and aiming to maximize the consumption of resources that Obx was created. Unlike GetX and GetBuilder, you will not be able to initialize a controller inside an Obx, it is just a Widget with a StreamSubscription that receives change events from your children, that's all. It is more economical than GetX, but loses to GetBuilder, which was to be expected, since it is reactive, and GetBuilder has the most simplistic approach that exists, of storing a widget's hashcode and its StateSetter. With Obx you don't need to write your controller type, and you can hear the change from multiple different controllers, but it needs to be initialized before, either using the example approach at the beginning of this readme, or using the Bindings class.
686 -Finally, some people opened a resource request, as they wanted to use only one type of reactive variable, and the other mechanics, and needed to insert an Obx into a GetBuilder for this. Thinking about it MixinBuilder was created. It allows both reactive changes by changing ".obs" variables, and mechanical updates via update(). However, of the 4 widgets he is the one that consumes the most resources, since in addition to having a Subscription to receive change events from his children, he subscribes to the update method of his controller.  
687 1032
688 -- Note: To use GetBuilder and MixinBuilder you must use GetController. To use GetX and Obx you must use RxController.  
689 -Probably using a GetController using GetX and Obx will work, but it will not be possible to use an RxController on a GetBuilder.  
690 -Extending these controllers is important, as they have life cycles, and can "start" and "end" events in their onInit() and onClose() methods. 1033 +
  1034 +
  1035 +
  1036 +# Dependency Management
  1037 +
691 1038
692 ## Simple Instance Manager 1039 ## Simple Instance Manager
693 - Note: If you are using Get's State Manager, you don't have to worry about that, just read for information, but pay more attention to the bindings api, which will do all of this automatically for you. 1040 - Note: If you are using Get's State Manager, you don't have to worry about that, just read for information, but pay more attention to the bindings api, which will do all of this automatically for you.
@@ -744,6 +1091,7 @@ To remove a instance of Get: @@ -744,6 +1091,7 @@ To remove a instance of Get:
744 Get.delete<Controller>(); 1091 Get.delete<Controller>();
745 ``` 1092 ```
746 1093
  1094 +
747 ## Bindings 1095 ## Bindings
748 One of the great differentials of this package, perhaps, is the possibility of full integration of the routes, state manager and dependency manager. 1096 One of the great differentials of this package, perhaps, is the possibility of full integration of the routes, state manager and dependency manager.
749 When a route is removed from the Stack, all controllers, variables, and instances of objects related to it are removed from memory. If you are using streams or timers, they will be closed automatically, and you don't have to worry about any of that. 1097 When a route is removed from the Stack, all controllers, variables, and instances of objects related to it are removed from memory. If you are using streams or timers, they will be closed automatically, and you don't have to worry about any of that.
@@ -753,7 +1101,7 @@ The Binding class is a class that will decouple dependency injection, while "bin @@ -753,7 +1101,7 @@ The Binding class is a class that will decouple dependency injection, while "bin
753 This allows Get to know which screen is being displayed when a particular controller is used and to know where and how to dispose of it. 1101 This allows Get to know which screen is being displayed when a particular controller is used and to know where and how to dispose of it.
754 In addition, the Binding class will allow you to have SmartManager configuration control. You can configure the dependencies to be arranged when removing a route from the stack, or when the widget that used it is laid out, or neither. You will have intelligent dependency management working for you, but even so, you can configure it as you wish. 1102 In addition, the Binding class will allow you to have SmartManager configuration control. You can configure the dependencies to be arranged when removing a route from the stack, or when the widget that used it is laid out, or neither. You will have intelligent dependency management working for you, but even so, you can configure it as you wish.
755 1103
756 -#### To use this API you only need: 1104 +### How to use
757 - Create a class and implements Binding 1105 - Create a class and implements Binding
758 1106
759 ```dart 1107 ```dart
@@ -794,7 +1142,7 @@ GetMaterialApp( @@ -794,7 +1142,7 @@ GetMaterialApp(
794 home: Home(), 1142 home: Home(),
795 ); 1143 );
796 ``` 1144 ```
797 - 1145 +## SmartManagement
798 Always prefer to use standard SmartManagement (full), you do not need to configure anything for that, Get already gives it to you by default. It will surely eliminate all your disused controllers from memory, as its refined control removes the dependency, even if a failure occurs and a widget that uses it is not properly disposed. 1146 Always prefer to use standard SmartManagement (full), you do not need to configure anything for that, Get already gives it to you by default. It will surely eliminate all your disused controllers from memory, as its refined control removes the dependency, even if a failure occurs and a widget that uses it is not properly disposed.
799 The "full" mode is also safe enough to be used with StatelessWidget, as it has numerous security callbacks that will prevent a controller from remaining in memory if it is not being used by any widget, and disposition is not important here. However, if you are bothered by the default behavior, or just don't want it to happen, Get offers other, more lenient options for intelligent memory management, such as SmartManagement.onlyBuilders, which will depend on the effective removal of widgets using the controller. tree to remove it, and you can prevent a controller from being deployed using "autoRemove: false" in your GetBuilder/GetX. 1147 The "full" mode is also safe enough to be used with StatelessWidget, as it has numerous security callbacks that will prevent a controller from remaining in memory if it is not being used by any widget, and disposition is not important here. However, if you are bothered by the default behavior, or just don't want it to happen, Get offers other, more lenient options for intelligent memory management, such as SmartManagement.onlyBuilders, which will depend on the effective removal of widgets using the controller. tree to remove it, and you can prevent a controller from being deployed using "autoRemove: false" in your GetBuilder/GetX.
800 With this option, only controllers started in "init:" or loaded into a Binding with "Get.lazyPut" will be disposed, if you use Get.put or any other approach, SmartManagement will not have permissions to exclude this dependency. 1148 With this option, only controllers started in "init:" or loaded into a Binding with "Get.lazyPut" will be disposed, if you use Get.put or any other approach, SmartManagement will not have permissions to exclude this dependency.
@@ -808,250 +1156,10 @@ Bindings creates transitory factories, which are created the moment you click to @@ -808,250 +1156,10 @@ Bindings creates transitory factories, which are created the moment you click to
808 - NOTE2: Using Bindings is completely optional, you can use Get.put() and Get.find() on classes that use a given controller without any problem. 1156 - NOTE2: Using Bindings is completely optional, you can use Get.put() and Get.find() on classes that use a given controller without any problem.
809 However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization. 1157 However, if you work with Services or any other abstraction, I recommend using Bindings for a larger organization.
810 1158
811 -## Workers:  
812 -Workers will assist you, triggering specific callbacks when an event occurs.  
813 -  
814 -  
815 -```dart  
816 -/// Called every time the variable $_ is changed  
817 -ever(count1, (_) => print("$_ has been changed"));  
818 -  
819 -/// Called only first time the variable $_ is changed  
820 -once(count1, (_) => print("$_ was changed once"));  
821 -  
822 -/// Anti DDos - Called every time the user stops typing for 1 second, for example.  
823 -debounce(count1, (_) => print("debouce$_"), time: Duration(seconds: 1));  
824 -  
825 -/// Ignore all changes within 1 second.  
826 -interval(count1, (_) => print("interval $_"), time: Duration(seconds: 1));  
827 -```  
828 -- ever  
829 -'ever' is called every time its variable is changed. That's it.  
830 -  
831 -- ever  
832 -'once' is called only the first time the variable has been changed.  
833 -  
834 -- debounce  
835 -'debounce' is very useful in search functions, where you only want the API to be called when the user finishes typing. If the user types "Jonny", you will have 5 searches in the APIs, by the letter J, o, n, n, and y. With Get this does not happen, because you will have a "debounce" Worker that will only be triggered at the end of typing.  
836 -  
837 -- interval  
838 -'interval' is different from the debouce. debouce if the user makes 1000 changes to a variable within 1 second, he will send only the last one after the stipulated timer (the default is 800 milliseconds). Interval will instead ignore all user actions for the stipulated period. If you send events for 1 minute, 1000 per second, debounce will only send you the last one, when the user stops strafing events. interval will deliver events every second, and if set to 3 seconds, it will deliver 20 events that minute. This is recommended to avoid abuse, in functions where the user can quickly click on something and get some advantage (imagine that the user can earn coins by clicking on something, if he clicked 300 times in the same minute, he would have 300 coins, using interval, you you can set a time frame for 3 seconds, and even then clicking 300 or a thousand times, the maximum he would get in 1 minute would be 20 coins, clicking 300 or 1 million times). The debounce is suitable for anti-DDos, for functions like search where each change to onChange would cause a query to your api. Debounce will wait for the user to stop typing the name, to make the request. If it were used in the coin scenario mentioned above, the user would only win 1 coin, because it is only executed, when the user "pauses" for the established time.  
839 -  
840 -  
841 -## Navigate with named routes:  
842 -- If you prefer to navigate by namedRoutes, Get also supports this.  
843 -  
844 -To navigate to nextScreen  
845 -```dart  
846 -Get.toNamed("/NextScreen");  
847 -```  
848 -To navigate and remove the previous screen from the tree.  
849 -```dart  
850 -Get.offNamed("/NextScreen");  
851 -```  
852 -To navigate and remove all previous screens from the tree.  
853 -```dart  
854 -Get.offAllNamed("/NextScreen");  
855 -```  
856 -  
857 -To define routes, use GetMaterialApp:  
858 -  
859 -```dart  
860 -void main() {  
861 - runApp(  
862 - GetMaterialApp(  
863 - initialRoute: '/',  
864 - namedRoutes: {  
865 - '/': GetRoute(page: MyHomePage()),  
866 - '/second': GetRoute(page: Second()),  
867 - '/third': GetRoute(page: Third(),transition: Transition.cupertino);  
868 - },  
869 - )  
870 - );  
871 -}  
872 -```  
873 -  
874 -### Send data to named Routes:  
875 -  
876 -Just send what you want for arguments. Get accepts anything here, whether it is a String, a Map, a List, or even a class instance.  
877 -```dart  
878 -Get.toNamed("/NextScreen", arguments: 'Get is the best');  
879 -```  
880 -on your class or controller:  
881 -  
882 -```dart  
883 -print(Get.arguments);  
884 -//print out: Get is the best  
885 -```  
886 -  
887 -#### Dynamic urls links  
888 -Get offer advanced dynamic urls just like on the Web. Web developers have probably already wanted this feature on Flutter, and most likely have seen a package promise this feature and deliver a totally different syntax than a URL would have on web, but Get also solves that.  
889 -  
890 -```dart  
891 -Get.offAllNamed("/NextScreen?device=phone&id=354&name=Enzo");  
892 -```  
893 -on your controller/bloc/stateful/stateless class:  
894 -  
895 -```dart  
896 -print(Get.parameters['id']);  
897 -// out: 354  
898 -print(Get.parameters['name']);  
899 -// out: Enzo  
900 -```  
901 -  
902 -You can also receive NamedParameters with Get easily:  
903 -  
904 -```dart  
905 -void main() {  
906 - runApp(  
907 - GetMaterialApp(  
908 - initialRoute: '/',  
909 - namedRoutes: {  
910 - '/': GetRoute(page: MyHomePage()),  
911 - /// Important! :user is not a new route, it is just a parameter  
912 - /// specification. Do not use '/second/:user' and '/second'  
913 - /// if you need new route to user, use '/second/user/:user'  
914 - /// if '/second' is a route.  
915 - '/second/:user': GetRoute(page: Second()), // receive ID  
916 - '/third': GetRoute(page: Third(),transition: Transition.cupertino);  
917 - },  
918 - )  
919 - );  
920 -}  
921 -```  
922 -Send data on route name  
923 -```dart  
924 -Get.toNamed("/second/34954");  
925 -```  
926 -  
927 -On second screen take the data by parameter  
928 -  
929 -```dart  
930 -print(Get.parameters['user']);  
931 -// out: 34954  
932 -```  
933 -  
934 -And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (you can call your routes directly from your BLoC or Controller class), and when your app is compiled to the web, your routes will appear in the url <3  
935 -  
936 1159
937 -#### Middleware  
938 -If you want listen Get events to trigger actions, you can to use routingCallback to it  
939 -```dart  
940 -GetMaterialApp(  
941 - routingCallback: (route) {  
942 - if(routing.current == '/second'){  
943 - openAds();  
944 - }  
945 - }  
946 -)  
947 -```  
948 -If you are not using GetMaterialApp, you can use the manual API to attach Middleware observer.  
949 -  
950 -```dart  
951 -void main() {  
952 - runApp(  
953 - MaterialApp(  
954 - onGenerateRoute: Router.generateRoute,  
955 - initialRoute: "/",  
956 - navigatorKey: Get.key,  
957 - navigatorObservers: [  
958 - GetObserver(MiddleWare.observer), // HERE !!!  
959 - ],  
960 - ),  
961 - );  
962 -}  
963 -```  
964 -Create a MiddleWare class 1160 +# Utils
965 1161
966 -```dart  
967 -class MiddleWare {  
968 - static observer(Routing routing) {  
969 - /// You can listen in addition to the routes, the snackbars, dialogs and bottomsheets on each screen.  
970 - ///If you need to enter any of these 3 events directly here,  
971 - ///you must specify that the event is != Than you are trying to do.  
972 - if (routing.current == '/second' && !routing.isSnackbar) {  
973 - Get.snackbar("Hi", "You are on second route");  
974 - } else if (routing.current =='/third'){  
975 - print('last route called');  
976 - }  
977 - }  
978 -}  
979 -```  
980 -  
981 -Now, use Get on your code:  
982 -  
983 -```dart  
984 -class First extends StatelessWidget {  
985 - @override  
986 - Widget build(BuildContext context) {  
987 - return Scaffold(  
988 - appBar: AppBar(  
989 - leading: IconButton(  
990 - icon: Icon(Icons.add),  
991 - onPressed: () {  
992 - Get.snackbar("hi", "i am a modern snackbar");  
993 - },  
994 - ),  
995 - title: Text('First Route'),  
996 - ),  
997 - body: Center(  
998 - child: RaisedButton(  
999 - child: Text('Open route'),  
1000 - onPressed: () {  
1001 - Get.toNamed("/second");  
1002 - },  
1003 - ),  
1004 - ),  
1005 - );  
1006 - }  
1007 -}  
1008 -  
1009 -class Second extends StatelessWidget {  
1010 - @override  
1011 - Widget build(BuildContext context) {  
1012 - return Scaffold(  
1013 - appBar: AppBar(  
1014 - leading: IconButton(  
1015 - icon: Icon(Icons.add),  
1016 - onPressed: () {  
1017 - Get.snackbar("hi", "i am a modern snackbar");  
1018 - },  
1019 - ),  
1020 - title: Text('second Route'),  
1021 - ),  
1022 - body: Center(  
1023 - child: RaisedButton(  
1024 - child: Text('Open route'),  
1025 - onPressed: () {  
1026 - Get.toNamed("/third");  
1027 - },  
1028 - ),  
1029 - ),  
1030 - );  
1031 - }  
1032 -}  
1033 -  
1034 -class Third extends StatelessWidget {  
1035 - @override  
1036 - Widget build(BuildContext context) {  
1037 - return Scaffold(  
1038 - appBar: AppBar(  
1039 - title: Text("Third Route"),  
1040 - ),  
1041 - body: Center(  
1042 - child: RaisedButton(  
1043 - onPressed: () {  
1044 - Get.back();  
1045 - },  
1046 - child: Text('Go back!'),  
1047 - ),  
1048 - ),  
1049 - );  
1050 - }  
1051 -}  
1052 -```  
1053 -  
1054 -### Change Theme 1162 +## Change Theme
1055 Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get. 1163 Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get.
1056 1164
1057 You can create your custom theme and simply add it within Get.changeTheme without any boilerplate for that: 1165 You can create your custom theme and simply add it within Get.changeTheme without any boilerplate for that:
@@ -1075,76 +1183,8 @@ If you want to know in depth how to change the theme, you can follow this tutori @@ -1075,76 +1183,8 @@ If you want to know in depth how to change the theme, you can follow this tutori
1075 - [Dynamic Themes in 3 lines using Get](https://medium.com/swlh/flutter-dynamic-themes-in-3-lines-c3b375f292e3) - Tutorial by [Rod Brown](https://github.com/RodBr). 1183 - [Dynamic Themes in 3 lines using Get](https://medium.com/swlh/flutter-dynamic-themes-in-3-lines-c3b375f292e3) - Tutorial by [Rod Brown](https://github.com/RodBr).
1076 1184
1077 1185
1078 -### Optional Global Settings  
1079 -You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp  
1080 -  
1081 -```dart  
1082 -GetMaterialApp(  
1083 - enableLog: true,  
1084 - defaultTransition: Transition.fade,  
1085 - opaqueRoute: Get.isOpaqueRouteDefault,  
1086 - popGesture: Get.isPopGestureEnable,  
1087 - transitionDuration: Get.defaultDurationTransition,  
1088 - defaultGlobalState: Get.defaultGlobalState,  
1089 -);  
1090 -  
1091 -Get.config(  
1092 - enableLog = true,  
1093 - defaultPopGesture = true,  
1094 - defaultTransition = Transitions.cupertino  
1095 -)  
1096 -```  
1097 -  
1098 -  
1099 -### Nested Navigators  
1100 -  
1101 -Get made Flutter's nested navigation even easier.  
1102 -You don't need the context, and you will find your navigation stack by Id.  
1103 -  
1104 -- NOTE: Creating parallel navigation stacks can be dangerous. The ideal is not to use NestedNavigators, or to use sparingly. If your project requires it, go ahead, but keep in mind that keeping multiple navigation stacks in memory may not be a good idea for RAM consumption.  
1105 -  
1106 -See how simple it is:  
1107 -```dart  
1108 -Navigator(  
1109 - key: Get.nestedKey(1), // create a key by index  
1110 - initialRoute: '/',  
1111 - onGenerateRoute: (settings) {  
1112 - if (settings.name == '/') {  
1113 - return GetRouteBase(  
1114 - page: Scaffold(  
1115 - appBar: AppBar(  
1116 - title: Text("Main"),  
1117 - ),  
1118 - body: Center(  
1119 - child: FlatButton(  
1120 - color: Colors.blue,  
1121 - onPressed: () {  
1122 - Get.toNamed('/second', id:1); // navigate by your nested route by index  
1123 - },  
1124 - child: Text("Go to second"),  
1125 - ),  
1126 - ),  
1127 - ),  
1128 - );  
1129 - } else if (settings.name == '/second') {  
1130 - return GetRouteBase(  
1131 - page: Center(  
1132 - child: Scaffold(  
1133 - appBar: AppBar(  
1134 - title: Text("Main"),  
1135 - ),  
1136 - body: Center(  
1137 - child: Text("second")  
1138 - ),  
1139 - ),  
1140 - ),  
1141 - );  
1142 - }  
1143 - }  
1144 -),  
1145 -```  
1146 1186
1147 -### Other Advanced APIs and Manual configurations 1187 +## Other Advanced APIs and Manual configurations
1148 GetMaterialApp configures everything for you, but if you want to configure Get Manually using advanced APIs. 1188 GetMaterialApp configures everything for you, but if you want to configure Get Manually using advanced APIs.
1149 1189
1150 ```dart 1190 ```dart
@@ -1198,4 +1238,27 @@ Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in th @@ -1198,4 +1238,27 @@ Get.contextOverlay // Gives the context of the snackbar/dialog/bottomsheet in th
1198 1238
1199 ``` 1239 ```
1200 1240
  1241 +
  1242 +### Optional Global Settings
  1243 +You can create Global settings for Get. Just add Get.config to your code before pushing any route or do it directly in your GetMaterialApp
  1244 +
  1245 +```dart
  1246 +GetMaterialApp(
  1247 + enableLog: true,
  1248 + defaultTransition: Transition.fade,
  1249 + opaqueRoute: Get.isOpaqueRouteDefault,
  1250 + popGesture: Get.isPopGestureEnable,
  1251 + transitionDuration: Get.defaultDurationTransition,
  1252 + defaultGlobalState: Get.defaultGlobalState,
  1253 +);
  1254 +
  1255 +Get.config(
  1256 + enableLog = true,
  1257 + defaultPopGesture = true,
  1258 + defaultTransition = Transitions.cupertino
  1259 +)
  1260 +```
  1261 +
  1262 +
  1263 +
1201 This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them. 1264 This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them.