Jonny Borges
Committed by GitHub

Merge pull request #1853 from maxzod/translation_readme

Translation readme
  1 +{
  2 + "cSpell.enableFiletypes": ["!markdown"]
  3 +}
  1 +![](https://raw.githubusercontent.com/jonataslaw/getx-community/master/get.png)
  2 +
  3 +[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
  4 +[![likes](https://badges.bar/get/likes)](https://pub.dev/packages/get/score)
  5 +![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
  6 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
  7 +[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
  8 +[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
  9 +[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
  10 +<a href="https://github.com/Solido/awesome-flutter">
  11 +<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
  12 +</a>
  13 +<a href="https://www.buymeacoffee.com/jonataslaw" target="_blank"><img src="https://i.imgur.com/aV6DDA7.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important; box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" > </a>
  14 +
  15 +![](https://raw.githubusercontent.com/jonataslaw/getx-community/master/getx.png)
  16 +
  17 +<div align="center">
  18 +
  19 +**Languages:**
  20 +
  21 +[![English](https://img.shields.io/badge/Language-English-blueviolet?style=for-the-badge)](README.md)
  22 +[![Vietnamese](https://img.shields.io/badge/Language-Vietnamese-blueviolet?style=for-the-badge)](README-vi.md)
  23 +[![Indonesian](https://img.shields.io/badge/Language-Indonesian-blueviolet?style=for-the-badge)](README.id-ID.md)
  24 +[![Urdu](https://img.shields.io/badge/Language-Urdu-blueviolet?style=for-the-badge)](README.ur-PK.md)
  25 +[![Chinese](https://img.shields.io/badge/Language-Chinese-blueviolet?style=for-the-badge)](README.zh-cn.md)
  26 +[![Portuguese](https://img.shields.io/badge/Language-Portuguese-blueviolet?style=for-the-badge)](README.pt-br.md)
  27 +[![Spanish](https://img.shields.io/badge/Language-Spanish-blueviolet?style=for-the-badge)](README-es.md)
  28 +[![Russian](https://img.shields.io/badge/Language-Russian-blueviolet?style=for-the-badge)](README.ru.md)
  29 +[![Polish](https://img.shields.io/badge/Language-Polish-blueviolet?style=for-the-badge)](README.pl.md)
  30 +[![Korean](https://img.shields.io/badge/Language-Korean-blueviolet?style=for-the-badge)](README.ko-kr.md)
  31 +[![French](https://img.shields.io/badge/Language-French-blueviolet?style=for-the-badge)](README-fr.md)
  32 +[![العربيه](https://img.shields.io/badge/Language-arabic-blueviolet?style=for-the-badge)](README-ar.md)
  33 +
  34 +</div>
  35 +<div dir="rtl">
  36 +
  37 +- [عن المكتبة](#عن-المكتبة)
  38 +- [التركيب](#التركيب)
  39 +- [بناء تطبيق العداد 🔢](#بناء-تطبيق-العداد-)
  40 +- [The Three pillars](#the-three-pillars)
  41 + - [State management](#state-management)
  42 + - [Reactive State Manager](#reactive-state-manager)
  43 + - [More details about state management](#more-details-about-state-management)
  44 + - [Route management](#route-management)
  45 + - [More details about route management](#more-details-about-route-management)
  46 + - [Dependency management](#dependency-management)
  47 + - [More details about dependency management](#more-details-about-dependency-management)
  48 +- [Utils](#utils)
  49 + - [Internationalization](#internationalization)
  50 + - [Translations](#translations)
  51 + - [Using translations](#using-translations)
  52 + - [Using translation with singular and plural](#using-translation-with-singular-and-plural)
  53 + - [Using translation with parameters](#using-translation-with-parameters)
  54 + - [Locales](#locales)
  55 + - [Change locale](#change-locale)
  56 + - [System locale](#system-locale)
  57 + - [Change Theme](#change-theme)
  58 + - [GetConnect](#getconnect)
  59 + - [Default configuration](#default-configuration)
  60 + - [Custom configuration](#custom-configuration)
  61 + - [GetPage Middleware](#getpage-middleware)
  62 + - [Priority](#priority)
  63 + - [Redirect](#redirect)
  64 + - [onPageCalled](#onpagecalled)
  65 + - [OnBindingsStart](#onbindingsstart)
  66 + - [OnPageBuildStart](#onpagebuildstart)
  67 + - [OnPageBuilt](#onpagebuilt)
  68 + - [OnPageDispose](#onpagedispose)
  69 + - [Other Advanced APIs](#other-advanced-apis)
  70 + - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations)
  71 + - [Local State Widgets](#local-state-widgets)
  72 + - [ValueBuilder](#valuebuilder)
  73 + - [ObxValue](#obxvalue)
  74 + - [Useful tips](#useful-tips)
  75 + - [StateMixin](#statemixin)
  76 + - [GetView](#getview)
  77 + - [GetResponsiveView](#getresponsiveview)
  78 + - [How to use it](#how-to-use-it)
  79 + - [GetWidget](#getwidget)
  80 + - [GetxService](#getxservice)
  81 + - [Tests](#tests)
  82 + - [Tips](#tips)
  83 + - [Mockito or mocktail](#mockito-or-mocktail)
  84 + - [Using Get.reset()](#using-getreset)
  85 + - [Get.testMode](#gettestmode)
  86 +- [Breaking changes from 2.0](#breaking-changes-from-20)
  87 +- [Why Getx?](#why-getx)
  88 +- [Community](#community)
  89 + - [Community channels](#community-channels)
  90 + - [How to contribute](#how-to-contribute)
  91 + - [Articles and videos](#articles-and-videos)
  92 +
  93 +# عن المكتبة
  94 +
  95 +- `GetX` مكتبه خفيفه وقوية لفلاتر , توفر المكتبه السرعه العاليه في التحكم في الحاله , نظام حقن `Ddependency injection` ذكي , والتحكم في التنقل بين الصفحات بسرعه وسهوله
  96 +
  97 +- `GetX`
  98 +- تعتمد علي 3 نقاط اساسية . **الانتاجية والسرعه والتنظيم**
  99 +
  100 + - **السرعه:** `GetX` تركز علي السرعه واقل استخدام للموارد,`GetX` لا تستخدم `Streams` او `ChangeNotifier`.
  101 +
  102 + - **الانتاجية:** `GetX` تستخدم طريقه سهله ومريحة في كتابة الكود , لا يهم ماذا تريد انت تبني , يوجد دائما طريقه اسهل لبناء باستخدام `GetX` , ستوفر ساعات من العمل وتوفر لك اعلي سرعه يمكن الوصل لها في تطبيقاتك عموما , يجب ان يهتم المطور بالتخلص من الموارد الغير مستخدمه من الذاكرة , مع `GetX` هذا غير ضروري لانه يتم التخلص من الموارد الغير مستخدمه من الذاكره تلقائيا, اذا اردت تركهم دائما في الذاكرة يمكنك ذلك لكن يجب عليك ان تستخدم `permanent: true` بالاضافه الي توفير الوقت تم تقليل امكانية ترك الموارد في الذاكره بدون التخلص منها , يتم حقن الموارد `lazy` افتراضيا
  103 +
  104 + - **التنظيم:** `GetX` تسمح لك بفصل الـ `view` عن الـ `presentation logic` و `business logic` باكامل,
  105 + بالنسبة للحقن `dependency injection` و التنقل بين الشاشات لا تحتاج فيهم `context` للتنقل بين الصفحات , ولا تحتاك `context` للوصول للموارد عن طريق widget tree, لذلك يتم الفصل بالكامل بين `presentation logic` و `business logic` لا تحتاج لحقن ال `Controllers/Models/Blocs`
  106 + داخل شجره العناصر `Widget Tree` خلال `MultiProvider`s.
  107 + لان , `GetX` تستخدم نظام حقن خاص بها ويمكنك من فصل الـ `DI` عن الوجهات بالكامل .
  108 +
  109 +- مع `Getx` تعرف ايه يكون الكود الخاص ب كل جزء في التطبيق , تساعدك في كتابة كود نظيف , بالاضافه الي سهوله التطوير مستقبلا , وهذا يمكنك من مشاركه الاجزاء `modules` امر صعب ليصبح سهل جدا .
  110 + `BLOC` كان نقطه البداية لهذا الامر وتظيم الكود بهذه الطريقه في فلاتر , عن طريق فصل كود البزنس عن الواجهات , `GetX` هي التطور لذلك الامر , وذلك عن طريق الاضافه الي ذلك فصل حقن الموارد وفصل التنقل بين الشاشات ايضا , وطبقه البيانات بالكامل ايضا , تعلم اين يكون كل شي في المشروع
  111 +
  112 +- `Getx` توفر لك السهوله في بناء المشروع والاستقرار كلما كبر حجم المشروع واقصي سرعه ممكن , توفر لك ايضا نظام كامل يعمل في تجانس تام , سهل للمبتدئين , ومنظم للخبراء , امن , مستقر , ومحدث باستمرار ويوفر لك موجموعه من الادوات لتسهل عليك
  113 +
  114 +- `GetX` ليست ضخمه , تمتلك المكتبة العديد من المميزات تجعلك تبدا في البرمجه بدون القلق عن اي شي كل ميزه منهم منقسمه عن الاخري ولا يبداو الا عندما تستخدمهم , اذا استخدمت جزء التحكم في الحاله فقط لن يتم استخدام جزء التنقل بين الشاشات في تطبيقك الا `Compiled` والعكس صحيح ! .
  115 +
  116 +-`Getx` لديها نظام شامل , ومجتمع كبير , وعداد كبير من المطورين , وسوف يتم تحديثها باستمرار , تعمل المكتبة علي كل الانظمه بنفس الكود دون تغيير `Android`, `iOS`, `Web`, `Mac`, `Linux`, `Windows` حتي علي الخادم يمكنك استخدام `Getx` لبناء تطبيقات الويب
  117 +**[Get Server](https://github.com/jonataslaw/get_server)**.
  118 +
  119 +**بالاضافه الي ذلك يمكن محاكاه الامر اكثر في فلاتر والخادم عن طريق [Get CLI](https://github.com/jonataslaw/get_cli)**.
  120 +
  121 +**وللمزيد من الانتاجية يمكنك استخدام اضافه للـ**
  122 +
  123 +- [فيجوال ستوديو كود](https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets)
  124 +- [اندرويد استوديو و انتلج](https://plugins.jetbrains.com/plugin/14975-getx-snippets)
  125 +
  126 +# التركيب
  127 +
  128 +استخدم المكتبة في ملف `pubspec.yaml`
  129 +
  130 +<div dir="ltr" >
  131 +
  132 +```yaml
  133 +dependencies:
  134 + get:
  135 +```
  136 +
  137 +</div>
  138 +استدعي المكتبة في الملفات الي ستستخدمها
  139 +<div dir="ltr" >
  140 +
  141 +```dart
  142 +import 'package:get/get.dart';
  143 +```
  144 +
  145 +</div>
  146 +
  147 +# بناء تطبيق العداد 🔢
  148 +
  149 +تطبيق العداد الذي يتم انشاء مع كل مشروع جديد يتعدي ال 100 سطر (بالتعليقات) ولكي اريك مدي قوه `GetX`
  150 +ساوضح لك كيفيه بناء التطبيق مع تغير قيمه العداد مع كل ضغطه زر والتقل بين الشاشات ومشاركه الحاله كل ذلك بطريقه منذمه وفصل تام لكود البزنس عن الواجهات فقط ب 26 سطر من ضمنهم التعليقات 🔥
  151 +
  152 +- الخطوه الاولي :
  153 + اكتب `Get` امام `MaterialApp` لتصبح `GetMaterialApp`
  154 +
  155 +<div dir="ltr" >
  156 +
  157 +```dart
  158 +void main() => runApp(GetMaterialApp(home: Home()));
  159 +```
  160 +
  161 +</div>
  162 +
  163 +- ملحوظه : هذا لا يعتبر تعديل علي `MaterialApp` لان , `GetMaterialApp` عباره عن عنصر معد مسبقا ويستخدم `MaterialApp` تحت الغطاء , يمكن تغير الاعدادات يدوين لكن هذا غير ضروري لان ``سيقوم بعمل المسارات و حقن العناصر والترجمه وكل شي تحتاجه ولكن اذا كنت تنوي لاستخدام المكتبة فقط للتحكم في الحاله`State managment`فهذه الخطوه غير ضرورية تكون هذه الخطوه ضرورية عندما تريد التنقل بين الشاشات او عرض`snackbars`والترجمه و اي شي يعتمد علي`context`وتقوم`getx` بتوفيره
  164 +
  165 +- الخطوه الثانية
  166 + قم بكتابة الكود داخل `class` وكتابة المتغيرات والدوال , يمكنك جعل المتغير قابلع لاعاده بناء الواجها عند تغير قيمته باستخدام ال `getter` `.obs` .
  167 +
  168 +<div dir="ltr" >
  169 +
  170 +```dart
  171 +class Controller extends GetxController{
  172 + var count = 0.obs;
  173 + increment() => count++;
  174 +}
  175 +```
  176 +
  177 +</div>
  178 +
  179 +- الخطوه الثالثه
  180 +ابني الواجهه واستخدم `StatelessWidget` لتوفير الموارد , مع `Getx` يمكنك الاستغناء عن `StatefulWidget`.
  181 +<div dir="ltr" >
  182 +
  183 +```dart
  184 +class Home extends StatelessWidget {
  185 +
  186 + @override
  187 + Widget build(context) {
  188 +
  189 + // Instantiate your class using Get.put() to make it available for all "child" routes there.
  190 + final c = Get.put(Controller());
  191 +
  192 + return Scaffold(
  193 + // Use Obx(()=> to update Text() whenever count is changed.
  194 + appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))),
  195 +
  196 + // Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context
  197 + body: Center(child: ElevatedButton(
  198 + child: Text("Go to Other"), onPressed: () => Get.to(Other()))),
  199 + floatingActionButton:
  200 + FloatingActionButton(child: Icon(Icons.add), onPressed: c.increment));
  201 + }
  202 +}
  203 +
  204 +class Other extends StatelessWidget {
  205 + // You can ask Get to find a Controller that is being used by another page and redirect you to it.
  206 + final Controller c = Get.find();
  207 +
  208 + @override
  209 + Widget build(context){
  210 + // Access the updated count variable
  211 + return Scaffold(body: Center(child: Text("${c.count}")));
  212 + }
  213 +}
  214 +```
  215 +
  216 +</div>
  217 +
  218 +Result:
  219 +
  220 +![](https://raw.githubusercontent.com/jonataslaw/getx-community/master/counter-app-gif.gif)
  221 +
  222 +This is a simple project but it already makes clear how powerful Get is. As your project grows, this difference will become more significant.
  223 +
  224 +Get was designed to work with teams, but it makes the job of an individual developer simple.
  225 +
  226 +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!
  227 +
  228 +# The Three pillars
  229 +
  230 +## State management
  231 +
  232 +Get has two different state managers: the simple state manager (we'll call it GetBuilder) and the reactive state manager (GetX/Obx)
  233 +
  234 +### Reactive State Manager
  235 +
  236 +Reactive programming can alienate many people because it is said to be complicated. GetX turns reactive programming into something quite simple:
  237 +
  238 +- You won't need to create StreamControllers.
  239 +- You won't need to create a StreamBuilder for each variable
  240 +- You will not need to create a class for each state.
  241 +- You will not need to create a get for an initial value.
  242 +- You will not need to use code generators
  243 +
  244 +Reactive programming with Get is as easy as using setState.
  245 +
  246 +Let's imagine that you have a name variable and want that every time you change it, all widgets that use it are automatically changed.
  247 +
  248 +This is your count variable:
  249 +
  250 +```dart
  251 +var name = 'Jonatas Borges';
  252 +```
  253 +
  254 +To make it observable, you just need to add ".obs" to the end of it:
  255 +
  256 +```dart
  257 +var name = 'Jonatas Borges'.obs;
  258 +```
  259 +
  260 +And in the UI, when you want to show that value and update the screen whenever the values changes, simply do this:
  261 +
  262 +```dart
  263 +Obx(() => Text("${controller.name}"));
  264 +```
  265 +
  266 +That's all. It's _that_ simple.
  267 +
  268 +### More details about state management
  269 +
  270 +**See an more in-depth explanation of state management [here](./documentation/en_US/state_management.md). There you will see more examples and also the difference between the simple state manager and the reactive state manager**
  271 +
  272 +You will get a good idea of GetX power.
  273 +
  274 +## Route management
  275 +
  276 +If you are going to use routes/snackbars/dialogs/bottomsheets without context, GetX is excellent for you too, just see it:
  277 +
  278 +Add "Get" before your MaterialApp, turning it into GetMaterialApp
  279 +
  280 +```dart
  281 +GetMaterialApp( // Before: MaterialApp(
  282 + home: MyHome(),
  283 +)
  284 +```
  285 +
  286 +Navigate to a new screen:
  287 +
  288 +```dart
  289 +
  290 +Get.to(NextScreen());
  291 +```
  292 +
  293 +Navigate to new screen with name. See more details on named routes [here](./documentation/en_US/route_management.md#navigation-with-named-routes)
  294 +
  295 +```dart
  296 +
  297 +Get.toNamed('/details');
  298 +```
  299 +
  300 +To close snackbars, dialogs, bottomsheets, or anything you would normally close with Navigator.pop(context);
  301 +
  302 +```dart
  303 +Get.back();
  304 +```
  305 +
  306 +To go to the next screen and no option to go back to the previous screen (for use in SplashScreens, login screens, etc.)
  307 +
  308 +```dart
  309 +Get.off(NextScreen());
  310 +```
  311 +
  312 +To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)
  313 +
  314 +```dart
  315 +Get.offAll(NextScreen());
  316 +```
  317 +
  318 +Noticed that you didn't have to use context to do any of these things? That's one of the biggest advantages of using Get route management. With this, you can execute all these methods from within your controller class, without worries.
  319 +
  320 +### More details about route management
  321 +
  322 +**Get works with named routes and also offers lower-level control over your routes! There is in-depth documentation [here](./documentation/en_US/route_management.md)**
  323 +
  324 +## Dependency management
  325 +
  326 +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:
  327 +
  328 +```dart
  329 +Controller controller = Get.put(Controller()); // Rather Controller controller = Controller();
  330 +```
  331 +
  332 +- Note: If you are using Get's State Manager, pay more attention to the bindings API, which will make it easier to connect your view to your controller.
  333 +
  334 +Instead of instantiating your class within the class you are using, you are instantiating it within the Get instance, which will make it available throughout your App.
  335 +So you can use your controller (or class Bloc) normally
  336 +
  337 +**Tip:** Get dependency management is decoupled from other parts of the package, so if for example, your app is already using a state manager (any one, it doesn't matter), you don't need to rewrite it all, you can use this dependency injection with no problems at all
  338 +
  339 +```dart
  340 +controller.fetchApi();
  341 +```
  342 +
  343 +Imagine that you have navigated through numerous routes, and you need data that was left behind in your controller, you would need a state manager combined with the Provider or Get_it, correct? Not with Get. You just need to ask Get to "find" for your controller, you don't need any additional dependencies:
  344 +
  345 +```dart
  346 +Controller controller = Get.find();
  347 +//Yes, it looks like Magic, Get will find your controller, and will deliver it to you. You can have 1 million controllers instantiated, Get will always give you the right controller.
  348 +```
  349 +
  350 +And then you will be able to recover your controller data that was obtained back there:
  351 +
  352 +```dart
  353 +Text(controller.textFromApi);
  354 +```
  355 +
  356 +### More details about dependency management
  357 +
  358 +**See a more in-depth explanation of dependency management [here](./documentation/en_US/dependency_management.md)**
  359 +
  360 +# Utils
  361 +
  362 +## Internationalization
  363 +
  364 +### Translations
  365 +
  366 +Translations are kept as a simple key-value dictionary map.
  367 +To add custom translations, create a class and extend `Translations`.
  368 +
  369 +```dart
  370 +import 'package:get/get.dart';
  371 +
  372 +class Messages extends Translations {
  373 + @override
  374 + Map<String, Map<String, String>> get keys => {
  375 + 'en_US': {
  376 + 'hello': 'Hello World',
  377 + },
  378 + 'de_DE': {
  379 + 'hello': 'Hallo Welt',
  380 + }
  381 + };
  382 +}
  383 +```
  384 +
  385 +#### Using translations
  386 +
  387 +Just append `.tr` to the specified key and it will be translated, using the current value of `Get.locale` and `Get.fallbackLocale`.
  388 +
  389 +```dart
  390 +Text('title'.tr);
  391 +```
  392 +
  393 +#### Using translation with singular and plural
  394 +
  395 +```dart
  396 +var products = [];
  397 +Text('singularKey'.trPlural('pluralKey', products.length, Args));
  398 +```
  399 +
  400 +#### Using translation with parameters
  401 +
  402 +```dart
  403 +import 'package:get/get.dart';
  404 +
  405 +
  406 +Map<String, Map<String, String>> get keys => {
  407 + 'en_US': {
  408 + 'logged_in': 'logged in as @name with email @email',
  409 + },
  410 + 'es_ES': {
  411 + 'logged_in': 'iniciado sesión como @name con e-mail @email',
  412 + }
  413 +};
  414 +
  415 +Text('logged_in'.trParams({
  416 + 'name': 'Jhon',
  417 + 'email': 'jhon@example.com'
  418 + }));
  419 +```
  420 +
  421 +### Locales
  422 +
  423 +Pass parameters to `GetMaterialApp` to define the locale and translations.
  424 +
  425 +```dart
  426 +return GetMaterialApp(
  427 + translations: Messages(), // your translations
  428 + locale: Locale('en', 'US'), // translations will be displayed in that locale
  429 + fallbackLocale: Locale('en', 'UK'), // specify the fallback locale in case an invalid locale is selected.
  430 +);
  431 +```
  432 +
  433 +#### Change locale
  434 +
  435 +Call `Get.updateLocale(locale)` to update the locale. Translations then automatically use the new locale.
  436 +
  437 +```dart
  438 +var locale = Locale('en', 'US');
  439 +Get.updateLocale(locale);
  440 +```
  441 +
  442 +#### System locale
  443 +
  444 +To read the system locale, you could use `Get.deviceLocale`.
  445 +
  446 +```dart
  447 +return GetMaterialApp(
  448 + locale: Get.deviceLocale,
  449 +);
  450 +```
  451 +
  452 +## Change Theme
  453 +
  454 +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 **GetX™**.
  455 +
  456 +You can create your custom theme and simply add it within `Get.changeTheme` without any boilerplate for that:
  457 +
  458 +```dart
  459 +Get.changeTheme(ThemeData.light());
  460 +```
  461 +
  462 +If you want to create something like a button that changes the Theme in `onTap`, you can combine two **GetX™** APIs for that:
  463 +
  464 +- The api that checks if the dark `Theme` is being used.
  465 +- And the `Theme` Change API, you can just put this within an `onPressed`:
  466 +
  467 +```dart
  468 +Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark());
  469 +```
  470 +
  471 +When `.darkmode` is activated, it will switch to the _light theme_, and when the _light theme_ becomes active, it will change to _dark theme_.
  472 +
  473 +## GetConnect
  474 +
  475 +GetConnect is an easy way to communicate from your back to your front with http or websockets
  476 +
  477 +### Default configuration
  478 +
  479 +You can simply extend GetConnect and use the GET/POST/PUT/DELETE/SOCKET methods to communicate with your Rest API or websockets.
  480 +
  481 +```dart
  482 +class UserProvider extends GetConnect {
  483 + // Get request
  484 + Future<Response> getUser(int id) => get('http://youapi/users/$id');
  485 + // Post request
  486 + Future<Response> postUser(Map data) => post('http://youapi/users', body: data);
  487 + // Post request with File
  488 + Future<Response<CasesModel>> postCases(List<int> image) {
  489 + final form = FormData({
  490 + 'file': MultipartFile(image, filename: 'avatar.png'),
  491 + 'otherFile': MultipartFile(image, filename: 'cover.png'),
  492 + });
  493 + return post('http://youapi/users/upload', form);
  494 + }
  495 +
  496 + GetSocket userMessages() {
  497 + return socket('https://yourapi/users/socket');
  498 + }
  499 +}
  500 +```
  501 +
  502 +### Custom configuration
  503 +
  504 +GetConnect is highly customizable You can define base Url, as answer modifiers, as Requests modifiers, define an authenticator, and even the number of attempts in which it will try to authenticate itself, in addition to giving the possibility to define a standard decoder that will transform all your requests into your Models without any additional configuration.
  505 +
  506 +```dart
  507 +class HomeProvider extends GetConnect {
  508 + @override
  509 + void onInit() {
  510 + // All request will pass to jsonEncode so CasesModel.fromJson()
  511 + httpClient.defaultDecoder = CasesModel.fromJson;
  512 + httpClient.baseUrl = 'https://api.covid19api.com';
  513 + // baseUrl = 'https://api.covid19api.com'; // It define baseUrl to
  514 + // Http and websockets if used with no [httpClient] instance
  515 +
  516 + // It's will attach 'apikey' property on header from all requests
  517 + httpClient.addRequestModifier((request) {
  518 + request.headers['apikey'] = '12345678';
  519 + return request;
  520 + });
  521 +
  522 + // Even if the server sends data from the country "Brazil",
  523 + // it will never be displayed to users, because you remove
  524 + // that data from the response, even before the response is delivered
  525 + httpClient.addResponseModifier<CasesModel>((request, response) {
  526 + CasesModel model = response.body;
  527 + if (model.countries.contains('Brazil')) {
  528 + model.countries.remove('Brazilll');
  529 + }
  530 + });
  531 +
  532 + httpClient.addAuthenticator((request) async {
  533 + final response = await get("http://yourapi/token");
  534 + final token = response.body['token'];
  535 + // Set the header
  536 + request.headers['Authorization'] = "$token";
  537 + return request;
  538 + });
  539 +
  540 + //Autenticator will be called 3 times if HttpStatus is
  541 + //HttpStatus.unauthorized
  542 + httpClient.maxAuthRetries = 3;
  543 + }
  544 + }
  545 +
  546 + @override
  547 + Future<Response<CasesModel>> getCases(String path) => get(path);
  548 +}
  549 +```
  550 +
  551 +## GetPage Middleware
  552 +
  553 +The GetPage has now new property that takes a list of GetMiddleWare and run them in the specific order.
  554 +
  555 +**Note**: When GetPage has a Middlewares, all the children of this page will have the same middlewares automatically.
  556 +
  557 +### Priority
  558 +
  559 +The Order of the Middlewares to run can be set by the priority in the GetMiddleware.
  560 +
  561 +```dart
  562 +final middlewares = [
  563 + GetMiddleware(priority: 2),
  564 + GetMiddleware(priority: 5),
  565 + GetMiddleware(priority: 4),
  566 + GetMiddleware(priority: -8),
  567 +];
  568 +```
  569 +
  570 +those middlewares will be run in this order **-8 => 2 => 4 => 5**
  571 +
  572 +### Redirect
  573 +
  574 +This function will be called when the page of the called route is being searched for. It takes RouteSettings as a result to redirect to. Or give it null and there will be no redirecting.
  575 +
  576 +```dart
  577 +RouteSettings redirect(String route) {
  578 + final authService = Get.find<AuthService>();
  579 + return authService.authed.value ? null : RouteSettings(name: '/login')
  580 +}
  581 +```
  582 +
  583 +### onPageCalled
  584 +
  585 +This function will be called when this Page is called before anything created
  586 +you can use it to change something about the page or give it new page
  587 +
  588 +```dart
  589 +GetPage onPageCalled(GetPage page) {
  590 + final authService = Get.find<AuthService>();
  591 + return page.copyWith(title: 'Welcome ${authService.UserName}');
  592 +}
  593 +```
  594 +
  595 +### OnBindingsStart
  596 +
  597 +This function will be called right before the Bindings are initialize.
  598 +Here you can change Bindings for this page.
  599 +
  600 +```dart
  601 +List<Bindings> onBindingsStart(List<Bindings> bindings) {
  602 + final authService = Get.find<AuthService>();
  603 + if (authService.isAdmin) {
  604 + bindings.add(AdminBinding());
  605 + }
  606 + return bindings;
  607 +}
  608 +```
  609 +
  610 +### OnPageBuildStart
  611 +
  612 +This function will be called right after the Bindings are initialize.
  613 +Here you can do something after that you created the bindings and before creating the page widget.
  614 +
  615 +```dart
  616 +GetPageBuilder onPageBuildStart(GetPageBuilder page) {
  617 + print('bindings are ready');
  618 + return page;
  619 +}
  620 +```
  621 +
  622 +### OnPageBuilt
  623 +
  624 +This function will be called right after the GetPage.page function is called and will give you the result of the function. and take the widget that will be showed.
  625 +
  626 +### OnPageDispose
  627 +
  628 +This function will be called right after disposing all the related objects (Controllers, views, ...) of the page.
  629 +
  630 +## Other Advanced APIs
  631 +
  632 +```dart
  633 +// give the current args from currentScreen
  634 +Get.arguments
  635 +
  636 +// give name of previous route
  637 +Get.previousRoute
  638 +
  639 +// give the raw route to access for example, rawRoute.isFirst()
  640 +Get.rawRoute
  641 +
  642 +// give access to Routing API from GetObserver
  643 +Get.routing
  644 +
  645 +// check if snackbar is open
  646 +Get.isSnackbarOpen
  647 +
  648 +// check if dialog is open
  649 +Get.isDialogOpen
  650 +
  651 +// check if bottomsheet is open
  652 +Get.isBottomSheetOpen
  653 +
  654 +// remove one route.
  655 +Get.removeRoute()
  656 +
  657 +// back repeatedly until the predicate returns true.
  658 +Get.until()
  659 +
  660 +// go to next route and remove all the previous routes until the predicate returns true.
  661 +Get.offUntil()
  662 +
  663 +// go to next named route and remove all the previous routes until the predicate returns true.
  664 +Get.offNamedUntil()
  665 +
  666 +//Check in what platform the app is running
  667 +GetPlatform.isAndroid
  668 +GetPlatform.isIOS
  669 +GetPlatform.isMacOS
  670 +GetPlatform.isWindows
  671 +GetPlatform.isLinux
  672 +GetPlatform.isFuchsia
  673 +
  674 +//Check the device type
  675 +GetPlatform.isMobile
  676 +GetPlatform.isDesktop
  677 +//All platforms are supported independently in web!
  678 +//You can tell if you are running inside a browser
  679 +//on Windows, iOS, OSX, Android, etc.
  680 +GetPlatform.isWeb
  681 +
  682 +
  683 +// Equivalent to : MediaQuery.of(context).size.height,
  684 +// but immutable.
  685 +Get.height
  686 +Get.width
  687 +
  688 +// Gives the current context of the Navigator.
  689 +Get.context
  690 +
  691 +// Gives the context of the snackbar/dialog/bottomsheet in the foreground, anywhere in your code.
  692 +Get.contextOverlay
  693 +
  694 +// Note: the following methods are extensions on context. Since you
  695 +// have access to context in any place of your UI, you can use it anywhere in the UI code
  696 +
  697 +// If you need a changeable height/width (like Desktop or browser windows that can be scaled) you will need to use context.
  698 +context.width
  699 +context.height
  700 +
  701 +// Gives you the power to define half the screen, a third of it and so on.
  702 +// Useful for responsive applications.
  703 +// param dividedBy (double) optional - default: 1
  704 +// param reducedBy (double) optional - default: 0
  705 +context.heightTransformer()
  706 +context.widthTransformer()
  707 +
  708 +/// Similar to MediaQuery.of(context).size
  709 +context.mediaQuerySize()
  710 +
  711 +/// Similar to MediaQuery.of(context).padding
  712 +context.mediaQueryPadding()
  713 +
  714 +/// Similar to MediaQuery.of(context).viewPadding
  715 +context.mediaQueryViewPadding()
  716 +
  717 +/// Similar to MediaQuery.of(context).viewInsets;
  718 +context.mediaQueryViewInsets()
  719 +
  720 +/// Similar to MediaQuery.of(context).orientation;
  721 +context.orientation()
  722 +
  723 +/// Check if device is on landscape mode
  724 +context.isLandscape()
  725 +
  726 +/// Check if device is on portrait mode
  727 +context.isPortrait()
  728 +
  729 +/// Similar to MediaQuery.of(context).devicePixelRatio;
  730 +context.devicePixelRatio()
  731 +
  732 +/// Similar to MediaQuery.of(context).textScaleFactor;
  733 +context.textScaleFactor()
  734 +
  735 +/// Get the shortestSide from screen
  736 +context.mediaQueryShortestSide()
  737 +
  738 +/// True if width be larger than 800
  739 +context.showNavbar()
  740 +
  741 +/// True if the shortestSide is smaller than 600p
  742 +context.isPhone()
  743 +
  744 +/// True if the shortestSide is largest than 600p
  745 +context.isSmallTablet()
  746 +
  747 +/// True if the shortestSide is largest than 720p
  748 +context.isLargeTablet()
  749 +
  750 +/// True if the current device is Tablet
  751 +context.isTablet()
  752 +
  753 +/// Returns a value<T> according to the screen size
  754 +/// can give value for:
  755 +/// watch: if the shortestSide is smaller than 300
  756 +/// mobile: if the shortestSide is smaller than 600
  757 +/// tablet: if the shortestSide is smaller than 1200
  758 +/// desktop: if width is largest than 1200
  759 +context.responsiveValue<T>()
  760 +```
  761 +
  762 +### Optional Global Settings and Manual configurations
  763 +
  764 +GetMaterialApp configures everything for you, but if you want to configure Get manually.
  765 +
  766 +```dart
  767 +MaterialApp(
  768 + navigatorKey: Get.key,
  769 + navigatorObservers: [GetObserver()],
  770 +);
  771 +```
  772 +
  773 +You will also be able to use your own Middleware within `GetObserver`, this will not influence anything.
  774 +
  775 +```dart
  776 +MaterialApp(
  777 + navigatorKey: Get.key,
  778 + navigatorObservers: [
  779 + GetObserver(MiddleWare.observer) // Here
  780 + ],
  781 +);
  782 +```
  783 +
  784 +You can create _Global Settings_ for `Get`. Just add `Get.config` to your code before pushing any route.
  785 +Or do it directly in your `GetMaterialApp`
  786 +
  787 +```dart
  788 +GetMaterialApp(
  789 + enableLog: true,
  790 + defaultTransition: Transition.fade,
  791 + opaqueRoute: Get.isOpaqueRouteDefault,
  792 + popGesture: Get.isPopGestureEnable,
  793 + transitionDuration: Get.defaultDurationTransition,
  794 + defaultGlobalState: Get.defaultGlobalState,
  795 +);
  796 +
  797 +Get.config(
  798 + enableLog = true,
  799 + defaultPopGesture = true,
  800 + defaultTransition = Transitions.cupertino
  801 +)
  802 +```
  803 +
  804 +You can optionally redirect all the logging messages from `Get`.
  805 +If you want to use your own, favourite logging package,
  806 +and want to capture the logs there:
  807 +
  808 +```dart
  809 +GetMaterialApp(
  810 + enableLog: true,
  811 + logWriterCallback: localLogWriter,
  812 +);
  813 +
  814 +void localLogWriter(String text, {bool isError = false}) {
  815 + // pass the message to your favourite logging package here
  816 + // please note that even if enableLog: false log messages will be pushed in this callback
  817 + // you get check the flag if you want through GetConfig.isLogEnable
  818 +}
  819 +
  820 +```
  821 +
  822 +### Local State Widgets
  823 +
  824 +These Widgets allows you to manage a single value, and keep the state ephemeral and locally.
  825 +We have flavours for Reactive and Simple.
  826 +For instance, you might use them to toggle obscureText in a `TextField`, maybe create a custom
  827 +Expandable Panel, or maybe modify the current index in `BottomNavigationBar` while changing the content
  828 +of the body in a `Scaffold`.
  829 +
  830 +#### ValueBuilder
  831 +
  832 +A simplification of `StatefulWidget` that works with a `.setState` callback that takes the updated value.
  833 +
  834 +```dart
  835 +ValueBuilder<bool>(
  836 + initialValue: false,
  837 + builder: (value, updateFn) => Switch(
  838 + value: value,
  839 + onChanged: updateFn, // same signature! you could use ( newValue ) => updateFn( newValue )
  840 + ),
  841 + // if you need to call something outside the builder method.
  842 + onUpdate: (value) => print("Value updated: $value"),
  843 + onDispose: () => print("Widget unmounted"),
  844 +),
  845 +```
  846 +
  847 +#### ObxValue
  848 +
  849 +Similar to [`ValueBuilder`](#valuebuilder), but this is the Reactive version, you pass a Rx instance (remember the magical .obs?) and
  850 +updates automatically... isn't it awesome?
  851 +
  852 +```dart
  853 +ObxValue((data) => Switch(
  854 + value: data.value,
  855 + onChanged: data, // Rx has a _callable_ function! You could use (flag) => data.value = flag,
  856 + ),
  857 + false.obs,
  858 +),
  859 +```
  860 +
  861 +## Useful tips
  862 +
  863 +`.obs`ervables (also known as _Rx_ Types) have a wide variety of internal methods and operators.
  864 +
  865 +> Is very common to _believe_ that a property with `.obs` **IS** the actual value... but make no mistake!
  866 +> We avoid the Type declaration of the variable, because Dart's compiler is smart enough, and the code
  867 +> looks cleaner, but:
  868 +
  869 +```dart
  870 +var message = 'Hello world'.obs;
  871 +print( 'Message "$message" has Type ${message.runtimeType}');
  872 +```
  873 +
  874 +Even if `message` _prints_ the actual String value, the Type is **RxString**!
  875 +
  876 +So, you can't do `message.substring( 0, 4 )`.
  877 +You have to access the real `value` inside the _observable_:
  878 +The most "used way" is `.value`, but, did you know that you can also use...
  879 +
  880 +```dart
  881 +final name = 'GetX'.obs;
  882 +// only "updates" the stream, if the value is different from the current one.
  883 +name.value = 'Hey';
  884 +
  885 +// All Rx properties are "callable" and returns the new value.
  886 +// but this approach does not accepts `null`, the UI will not rebuild.
  887 +name('Hello');
  888 +
  889 +// is like a getter, prints 'Hello'.
  890 +name() ;
  891 +
  892 +/// numbers:
  893 +
  894 +final count = 0.obs;
  895 +
  896 +// You can use all non mutable operations from num primitives!
  897 +count + 1;
  898 +
  899 +// Watch out! this is only valid if `count` is not final, but var
  900 +count += 1;
  901 +
  902 +// You can also compare against values:
  903 +count > 2;
  904 +
  905 +/// booleans:
  906 +
  907 +final flag = false.obs;
  908 +
  909 +// switches the value between true/false
  910 +flag.toggle();
  911 +
  912 +
  913 +/// all types:
  914 +
  915 +// Sets the `value` to null.
  916 +flag.nil();
  917 +
  918 +// All toString(), toJson() operations are passed down to the `value`
  919 +print( count ); // calls `toString()` inside for RxInt
  920 +
  921 +final abc = [0,1,2].obs;
  922 +// Converts the value to a json Array, prints RxList
  923 +// Json is supported by all Rx types!
  924 +print('json: ${jsonEncode(abc)}, type: ${abc.runtimeType}');
  925 +
  926 +// RxMap, RxList and RxSet are special Rx types, that extends their native types.
  927 +// but you can work with a List as a regular list, although is reactive!
  928 +abc.add(12); // pushes 12 to the list, and UPDATES the stream.
  929 +abc[3]; // like Lists, reads the index 3.
  930 +
  931 +
  932 +// equality works with the Rx and the value, but hashCode is always taken from the value
  933 +final number = 12.obs;
  934 +print( number == 12 ); // prints > true
  935 +
  936 +/// Custom Rx Models:
  937 +
  938 +// toJson(), toString() are deferred to the child, so you can implement override on them, and print() the observable directly.
  939 +
  940 +class User {
  941 + String name, last;
  942 + int age;
  943 + User({this.name, this.last, this.age});
  944 +
  945 + @override
  946 + String toString() => '$name $last, $age years old';
  947 +}
  948 +
  949 +final user = User(name: 'John', last: 'Doe', age: 33).obs;
  950 +
  951 +// `user` is "reactive", but the properties inside ARE NOT!
  952 +// So, if we change some variable inside of it...
  953 +user.value.name = 'Roi';
  954 +// The widget will not rebuild!,
  955 +// `Rx` don't have any clue when you change something inside user.
  956 +// So, for custom classes, we need to manually "notify" the change.
  957 +user.refresh();
  958 +
  959 +// or we can use the `update()` method!
  960 +user.update((value){
  961 + value.name='Roi';
  962 +});
  963 +
  964 +print( user );
  965 +```
  966 +
  967 +## StateMixin
  968 +
  969 +Another way to handle your `UI` state is use the `StateMixin<T>` .
  970 +To implement it, use the `with` to add the `StateMixin<T>`
  971 +to your controller which allows a T model.
  972 +
  973 +```dart
  974 +class Controller extends GetController with StateMixin<User>{}
  975 +```
  976 +
  977 +The `change()` method change the State whenever we want.
  978 +Just pass the data and the status in this way:
  979 +
  980 +```dart
  981 +change(data, status: RxStatus.success());
  982 +```
  983 +
  984 +RxStatus allow these status:
  985 +
  986 +```dart
  987 +RxStatus.loading();
  988 +RxStatus.success();
  989 +RxStatus.empty();
  990 +RxStatus.error('message');
  991 +```
  992 +
  993 +To represent it in the UI, use:
  994 +
  995 +```dart
  996 +class OtherClass extends GetView<Controller> {
  997 + @override
  998 + Widget build(BuildContext context) {
  999 + return Scaffold(
  1000 +
  1001 + body: controller.obx(
  1002 + (state)=>Text(state.name),
  1003 +
  1004 + // here you can put your custom loading indicator, but
  1005 + // by default would be Center(child:CircularProgressIndicator())
  1006 + onLoading: CustomLoadingIndicator(),
  1007 + onEmpty: Text('No data found'),
  1008 +
  1009 + // here also you can set your own error widget, but by
  1010 + // default will be an Center(child:Text(error))
  1011 + onError: (error)=>Text(error),
  1012 + ),
  1013 + );
  1014 +}
  1015 +```
  1016 +
  1017 +#### GetView
  1018 +
  1019 +I love this Widget, is so simple, yet, so useful!
  1020 +
  1021 +Is a `const Stateless` Widget that has a getter `controller` for a registered `Controller`, that's all.
  1022 +
  1023 +```dart
  1024 + class AwesomeController extends GetController {
  1025 + final String title = 'My Awesome View';
  1026 + }
  1027 +
  1028 + // ALWAYS remember to pass the `Type` you used to register your controller!
  1029 + class AwesomeView extends GetView<AwesomeController> {
  1030 + @override
  1031 + Widget build(BuildContext context) {
  1032 + return Container(
  1033 + padding: EdgeInsets.all(20),
  1034 + child: Text(controller.title), // just call `controller.something`
  1035 + );
  1036 + }
  1037 + }
  1038 +```
  1039 +
  1040 +#### GetResponsiveView
  1041 +
  1042 +Extend this widget to build responsive view.
  1043 +this widget contains the `screen` property that have all
  1044 +information about the screen size and type.
  1045 +
  1046 +##### How to use it
  1047 +
  1048 +You have two options to build it.
  1049 +
  1050 +- with `builder` method you return the widget to build.
  1051 +- with methods `desktop`, `tablet`,`phone`, `watch`. the specific
  1052 + method will be built when the screen type matches the method
  1053 + when the screen is [ScreenType.Tablet] the `tablet` method
  1054 + will be exuded and so on.
  1055 + **Note:** If you use this method please set the property `alwaysUseBuilder` to `false`
  1056 +
  1057 +With `settings` property you can set the width limit for the screen types.
  1058 +
  1059 +![example](https://github.com/SchabanBo/get_page_example/blob/master/docs/Example.gif?raw=true)
  1060 +Code to this screen
  1061 +[code](https://github.com/SchabanBo/get_page_example/blob/master/lib/pages/responsive_example/responsive_view.dart)
  1062 +
  1063 +#### GetWidget
  1064 +
  1065 +Most people have no idea about this Widget, or totally confuse the usage of it.
  1066 +The use case is very rare, but very specific: It `caches` a Controller.
  1067 +Because of the _cache_, can't be a `const Stateless`.
  1068 +
  1069 +> So, when do you need to "cache" a Controller?
  1070 +
  1071 +If you use, another "not so common" feature of **GetX**: `Get.create()`.
  1072 +
  1073 +`Get.create(()=>Controller())` will generate a new `Controller` each time you call
  1074 +`Get.find<Controller>()`,
  1075 +
  1076 +That's where `GetWidget` shines... as you can use it, for example,
  1077 +to keep a list of Todo items. So, if the widget gets "rebuilt", it will keep the same controller instance.
  1078 +
  1079 +#### GetxService
  1080 +
  1081 +This class is like a `GetxController`, it shares the same lifecycle ( `onInit()`, `onReady()`, `onClose()`).
  1082 +But has no "logic" inside of it. It just notifies **GetX** Dependency Injection system, that this subclass
  1083 +**can not** be removed from memory.
  1084 +
  1085 +So is super useful to keep your "Services" always reachable and active with `Get.find()`. Like:
  1086 +`ApiService`, `StorageService`, `CacheService`.
  1087 +
  1088 +```dart
  1089 +Future<void> main() async {
  1090 + await initServices(); /// AWAIT SERVICES INITIALIZATION.
  1091 + runApp(SomeApp());
  1092 +}
  1093 +
  1094 +/// Is a smart move to make your Services intiialize before you run the Flutter app.
  1095 +/// as you can control the execution flow (maybe you need to load some Theme configuration,
  1096 +/// apiKey, language defined by the User... so load SettingService before running ApiService.
  1097 +/// so GetMaterialApp() doesnt have to rebuild, and takes the values directly.
  1098 +void initServices() async {
  1099 + print('starting services ...');
  1100 + /// Here is where you put get_storage, hive, shared_pref initialization.
  1101 + /// or moor connection, or whatever that's async.
  1102 + await Get.putAsync(() => DbService().init());
  1103 + await Get.putAsync(SettingsService()).init();
  1104 + print('All services started...');
  1105 +}
  1106 +
  1107 +class DbService extends GetxService {
  1108 + Future<DbService> init() async {
  1109 + print('$runtimeType delays 2 sec');
  1110 + await 2.delay();
  1111 + print('$runtimeType ready!');
  1112 + return this;
  1113 + }
  1114 +}
  1115 +
  1116 +class SettingsService extends GetxService {
  1117 + void init() async {
  1118 + print('$runtimeType delays 1 sec');
  1119 + await 1.delay();
  1120 + print('$runtimeType ready!');
  1121 + }
  1122 +}
  1123 +
  1124 +```
  1125 +
  1126 +The only way to actually delete a `GetxService`, is with `Get.reset()` which is like a
  1127 +"Hot Reboot" of your app. So remember, if you need absolute persistence of a class instance during the
  1128 +lifetime of your app, use `GetxService`.
  1129 +
  1130 +### Tests
  1131 +
  1132 +You can test your controllers like any other class, including their lifecycles:
  1133 +
  1134 +```dart
  1135 +class Controller extends GetxController {
  1136 + @override
  1137 + void onInit() {
  1138 + super.onInit();
  1139 + //Change value to name2
  1140 + name.value = 'name2';
  1141 + }
  1142 +
  1143 + @override
  1144 + void onClose() {
  1145 + name.value = '';
  1146 + super.onClose();
  1147 + }
  1148 +
  1149 + final name = 'name1'.obs;
  1150 +
  1151 + void changeName() => name.value = 'name3';
  1152 +}
  1153 +
  1154 +void main() {
  1155 + test('''
  1156 +Test the state of the reactive variable "name" across all of its lifecycles''',
  1157 + () {
  1158 + /// You can test the controller without the lifecycle,
  1159 + /// but it's not recommended unless you're not using
  1160 + /// GetX dependency injection
  1161 + final controller = Controller();
  1162 + expect(controller.name.value, 'name1');
  1163 +
  1164 + /// If you are using it, you can test everything,
  1165 + /// including the state of the application after each lifecycle.
  1166 + Get.put(controller); // onInit was called
  1167 + expect(controller.name.value, 'name2');
  1168 +
  1169 + /// Test your functions
  1170 + controller.changeName();
  1171 + expect(controller.name.value, 'name3');
  1172 +
  1173 + /// onClose was called
  1174 + Get.delete<Controller>();
  1175 +
  1176 + expect(controller.name.value, '');
  1177 + });
  1178 +}
  1179 +```
  1180 +
  1181 +#### Tips
  1182 +
  1183 +##### Mockito or mocktail
  1184 +
  1185 +If you need to mock your GetxController/GetxService, you should extend GetxController, and mixin it with Mock, that way
  1186 +
  1187 +```dart
  1188 +class NotificationServiceMock extends GetxService with Mock implements NotificationService {}
  1189 +```
  1190 +
  1191 +##### Using Get.reset()
  1192 +
  1193 +If you are testing widgets, or test groups, use Get.reset at the end of your test or in tearDown to reset all settings from your previous test.
  1194 +
  1195 +##### Get.testMode
  1196 +
  1197 +if you are using your navigation in your controllers, use `Get.testMode = true` at the beginning of your main.
  1198 +
  1199 +# Breaking changes from 2.0
  1200 +
  1201 +1- Rx types:
  1202 +
  1203 +| Before | After |
  1204 +| ------- | ---------- |
  1205 +| StringX | `RxString` |
  1206 +| IntX | `RxInt` |
  1207 +| MapX | `RxMap` |
  1208 +| ListX | `RxList` |
  1209 +| NumX | `RxNum` |
  1210 +| DoubleX | `RxDouble` |
  1211 +
  1212 +RxController and GetBuilder now have merged, you no longer need to memorize which controller you want to use, just use GetxController, it will work for simple state management and for reactive as well.
  1213 +
  1214 +2- NamedRoutes
  1215 +Before:
  1216 +
  1217 +```dart
  1218 +GetMaterialApp(
  1219 + namedRoutes: {
  1220 + '/': GetRoute(page: Home()),
  1221 + }
  1222 +)
  1223 +```
  1224 +
  1225 +Now:
  1226 +
  1227 +```dart
  1228 +GetMaterialApp(
  1229 + getPages: [
  1230 + GetPage(name: '/', page: () => Home()),
  1231 + ]
  1232 +)
  1233 +```
  1234 +
  1235 +Why this change?
  1236 +Often, it may be necessary to decide which page will be displayed from a parameter, or a login token, the previous approach was inflexible, as it did not allow this.
  1237 +Inserting the page into a function has significantly reduced the RAM consumption, since the routes will not be allocated in memory since the app was started, and it also allowed to do this type of approach:
  1238 +
  1239 +```dart
  1240 +
  1241 +GetStorage box = GetStorage();
  1242 +
  1243 +GetMaterialApp(
  1244 + getPages: [
  1245 + GetPage(name: '/', page:(){
  1246 + return box.hasData('token') ? Home() : Login();
  1247 + })
  1248 + ]
  1249 +)
  1250 +```
  1251 +
  1252 +# Why Getx?
  1253 +
  1254 +1- Many times after a Flutter update, many of your packages will break. Sometimes compilation errors happen, errors often appear that there are still no answers about, and the developer needs to know where the error came from, track the error, only then try to open an issue in the corresponding repository, and see its problem solved. Get centralizes the main resources for development (State, dependency and route management), allowing you to add a single package to your pubspec, and start working. After a Flutter update, the only thing you need to do is update the Get dependency, and get to work. Get also resolves compatibility issues. How many times a version of a package is not compatible with the version of another, because one uses a dependency in one version, and the other in another version? This is also not a concern using Get, as everything is in the same package and is fully compatible.
  1255 +
  1256 +2- Flutter is easy, Flutter is incredible, but Flutter still has some boilerplate that may be unwanted for most developers, such as `Navigator.of(context).push (context, builder [...]`. Get simplifies development. Instead of writing 8 lines of code to just call a route, you can just do it: `Get.to(Home())` and you're done, you'll go to the next page. Dynamic web urls are a really painful thing to do with Flutter currently, and that with GetX is stupidly simple. Managing states in Flutter, and managing dependencies is also something that generates a lot of discussion, as there are hundreds of patterns in the pub. But there is nothing as easy as adding a ".obs" at the end of your variable, and place your widget inside an Obx, and that's it, all updates to that variable will be automatically updated on the screen.
  1257 +
  1258 +3- Ease without worrying about performance. Flutter's performance is already amazing, but imagine that you use a state manager, and a locator to distribute your blocs/stores/controllers/ etc. classes. You will have to manually call the exclusion of that dependency when you don't need it. But have you ever thought of simply using your controller, and when it was no longer being used by anyone, it would simply be deleted from memory? That's what GetX does. With SmartManagement, everything that is not being used is deleted from memory, and you shouldn't have to worry about anything but programming. You will be assured that you are consuming the minimum necessary resources, without even having created a logic for this.
  1259 +
  1260 +4- Actual decoupling. You may have heard the concept "separate the view from the business logic". This is not a peculiarity of BLoC, MVC, MVVM, and any other standard on the market has this concept. However, this concept can often be mitigated in Flutter due to the use of context.
  1261 +If you need context to find an InheritedWidget, you need it in the view, or pass the context by parameter. I particularly find this solution very ugly, and to work in teams we will always have a dependence on View's business logic. Getx is unorthodox with the standard approach, and while it does not completely ban the use of StatefulWidgets, InitState, etc., it always has a similar approach that can be cleaner. Controllers have life cycles, and when you need to make an APIREST request for example, you don't depend on anything in the view. You can use onInit to initiate the http call, and when the data arrives, the variables will be populated. As GetX is fully reactive (really, and works under streams), once the items are filled, all widgets that use that variable will be automatically updated in the view. This allows people with UI expertise to work only with widgets, and not have to send anything to business logic other than user events (like clicking a button), while people working with business logic will be free to create and test the business logic separately.
  1262 +
  1263 +This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them.
  1264 +
  1265 +# Community
  1266 +
  1267 +## Community channels
  1268 +
  1269 +GetX has a highly active and helpful community. If you have questions, or would like any assistance regarding the use of this framework, please join our community channels, your question will be answered more quickly, and it will be the most suitable place. This repository is exclusive for opening issues, and requesting resources, but feel free to be part of GetX Community.
  1270 +
  1271 +| **Slack** | **Discord** | **Telegram** |
  1272 +| :-------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
  1273 +| [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx) | [![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N) | [![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g) |
  1274 +
  1275 +## How to contribute
  1276 +
  1277 +_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._
  1278 +
  1279 +- Helping to translate the readme into other languages.
  1280 +- Adding documentation to the readme (a lot of Get's functions haven't been documented yet).
  1281 +- Write articles or make videos teaching how to use Get (they will be inserted in the Readme and in the future in our Wiki).
  1282 +- Offering PRs for code/tests.
  1283 +- Including new functions.
  1284 +
  1285 +Any contribution is welcome!
  1286 +
  1287 +## Articles and videos
  1288 +
  1289 +- [Flutter Getx EcoSystem package for arabic people](https://www.youtube.com/playlist?list=PLV1fXIAyjeuZ6M8m56zajMUwu4uE3-SL0) - Tutorial by [Pesa Coder](https://github.com/UsamaElgendy).
  1290 +- [Dynamic Themes in 3 lines using GetX™](https://medium.com/swlh/flutter-dynamic-themes-in-3-lines-c3b375f292e3) - Tutorial by [Rod Brown](https://github.com/RodBr).
  1291 +- [Complete GetX™ Navigation](https://www.youtube.com/watch?v=RaqPIoJSTtI) - Route management video by Amateur Coder.
  1292 +- [Complete GetX State Management](https://www.youtube.com/watch?v=CNpXbeI_slw) - State management video by Amateur Coder.
  1293 +- [GetX™ Other Features](https://youtu.be/ttQtlX_Q0eU) - Utils, storage, bindings and other features video by Amateur Coder.
  1294 +- [Firestore User with GetX | Todo App](https://www.youtube.com/watch?v=BiV0DcXgk58) - Video by Amateur Coder.
  1295 +- [Firebase Auth with GetX | Todo App](https://www.youtube.com/watch?v=-H-T_BSgfOE) - Video by Amateur Coder.
  1296 +- [The Flutter GetX™ Ecosystem ~ State Management](https://medium.com/flutter-community/the-flutter-getx-ecosystem-state-management-881c7235511d) - State management by [Aachman Garg](https://github.com/imaachman).
  1297 +- [The Flutter GetX™ Ecosystem ~ Dependency Injection](https://medium.com/flutter-community/the-flutter-getx-ecosystem-dependency-injection-8e763d0ec6b9) - Dependency Injection by [Aachman Garg](https://github.com/imaachman).
  1298 +- [GetX, the all-in-one Flutter package](https://www.youtube.com/watch?v=IYQgtu9TM74) - A brief tutorial covering State Management and Navigation by Thad Carnevalli.
  1299 +- [Build a To-do List App from scratch using Flutter and GetX](https://www.youtube.com/watch?v=EcnqFasHf18) - UI + State Management + Storage video by Thad Carnevalli.
  1300 +- [GetX Flutter Firebase Auth Example](https://medium.com/@jeffmcmorris/getx-flutter-firebase-auth-example-b383c1dd1de2) - Article by Jeff McMorris.
  1301 +- [Flutter State Management with GetX – Complete App](https://www.appwithflutter.com/flutter-state-management-with-getx/) - by App With Flutter.
  1302 +- [Flutter Routing with Animation using Get Package](https://www.appwithflutter.com/flutter-routing-using-get-package/) - by App With Flutter.
  1303 +- [A minimal example on dartpad](https://dartpad.dev/2b3d0d6f9d4e312c5fdbefc414c1727e?) - by [Roi Peker](https://github.com/roipeker)
  1304 +
  1305 +</div>
  1 +# Dependency Management
  2 +- [Dependency Management](#dependency-management)
  3 + - [Instancing methods](#instancing-methods)
  4 + - [Get.put()](#getput)
  5 + - [Get.lazyPut](#getlazyput)
  6 + - [Get.putAsync](#getputasync)
  7 + - [Get.create](#getcreate)
  8 + - [Using instantiated methods/classes](#using-instantiated-methodsclasses)
  9 + - [Specifying an alternate instance](#specifying-an-alternate-instance)
  10 + - [Differences between methods](#differences-between-methods)
  11 + - [Bindings](#bindings)
  12 + - [Bindings class](#bindings-class)
  13 + - [BindingsBuilder](#bindingsbuilder)
  14 + - [SmartManagement](#smartmanagement)
  15 + - [How to change](#how-to-change)
  16 + - [SmartManagement.full](#smartmanagementfull)
  17 + - [SmartManagement.onlyBuilders](#smartmanagementonlybuilders)
  18 + - [SmartManagement.keepFactory](#smartmanagementkeepfactory)
  19 + - [How bindings work under the hood](#how-bindings-work-under-the-hood)
  20 + - [Notes](#notes)
  21 +
  22 +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:
  23 +
  24 +```dart
  25 +Controller controller = Get.put(Controller()); // Rather Controller controller = Controller();
  26 +```
  27 +
  28 +Instead of instantiating your class within the class you are using, you are instantiating it within the Get instance, which will make it available throughout your App.
  29 +So you can use your controller (or Bloc class) normally
  30 +
  31 +- Note: If you are using Get's State Manager, pay more attention to the [Bindings](#bindings) api, which will make easier to connect your view to your controller.
  32 +- Note²: Get dependency management is decloupled from other parts of the package, so if for example your app is already using a state manager (any one, it doesn't matter), you don't need to change that, you can use this dependency injection manager with no problems at all
  33 +
  34 +## Instancing methods
  35 +The methods and it's configurable parameters are:
  36 +
  37 +### Get.put()
  38 +
  39 +The most common way of inserting a dependency. Good for the controllers of your views for example.
  40 +
  41 +```dart
  42 +Get.put<SomeClass>(SomeClass());
  43 +Get.put<LoginController>(LoginController(), permanent: true);
  44 +Get.put<ListItemController>(ListItemController, tag: "some unique string");
  45 +```
  46 +
  47 +This is all options you can set when using put:
  48 +```dart
  49 +Get.put<S>(
  50 + // mandatory: the class that you want to get to save, like a controller or anything
  51 + // note: "S" means that it can be a class of any type
  52 + S dependency
  53 +
  54 + // optional: this is for when you want multiple classess that are of the same type
  55 + // since you normally get a class by using Get.find<Controller>(),
  56 + // you need to use tag to tell which instance you need
  57 + // must be unique string
  58 + String tag,
  59 +
  60 + // optional: by default, get will dispose instances after they are not used anymore (example,
  61 + // the controller of a view that is closed), but you might need that the instance
  62 + // to be kept there throughout the entire app, like an instance of sharedPreferences or something
  63 + // so you use this
  64 + // defaults to false
  65 + bool permanent = false,
  66 +
  67 + // optional: allows you after using an abstract class in a test, replace it with another one and follow the test.
  68 + // defaults to false
  69 + bool overrideAbstract = false,
  70 +
  71 + // optional: allows you to create the dependency using function instead of the dependency itself.
  72 + // this one is not commonly used
  73 + InstanceBuilderCallback<S> builder,
  74 +)
  75 +```
  76 +
  77 +### Get.lazyPut
  78 +It is possible to lazyLoad a dependency so that it will be instantiated only when is used. Very useful for computational expensive classes or if you want to instantiate several classes in just one place (like in a Bindings class) and you know you will not gonna use that class at that time.
  79 +
  80 +```dart
  81 +/// ApiMock will only be called when someone uses Get.find<ApiMock> for the first time
  82 +Get.lazyPut<ApiMock>(() => ApiMock());
  83 +
  84 +Get.lazyPut<FirebaseAuth>(
  85 + () {
  86 + // ... some logic if needed
  87 + return FirebaseAuth();
  88 + },
  89 + tag: Math.random().toString(),
  90 + fenix: true
  91 +)
  92 +
  93 +Get.lazyPut<Controller>( () => Controller() )
  94 +```
  95 +
  96 +This is all options you can set when using lazyPut:
  97 +```dart
  98 +Get.lazyPut<S>(
  99 + // mandatory: a method that will be executed when your class is called for the first time
  100 + InstanceBuilderCallback builder,
  101 +
  102 + // optional: same as Get.put(), it is used for when you want multiple different instance of a same class
  103 + // must be unique
  104 + String tag,
  105 +
  106 + // optional: It is similar to "permanent", the difference is that the instance is discarded when
  107 + // is not being used, but when it's use is needed again, Get will recreate the instance
  108 + // just the same as "SmartManagement.keepFactory" in the bindings api
  109 + // defaults to false
  110 + bool fenix = false
  111 +
  112 +)
  113 +```
  114 +
  115 +### Get.putAsync
  116 +If you want to register an asynchronous instance, you can use `Get.putAsync`:
  117 +
  118 +```dart
  119 +Get.putAsync<SharedPreferences>(() async {
  120 + final prefs = await SharedPreferences.getInstance();
  121 + await prefs.setInt('counter', 12345);
  122 + return prefs;
  123 +});
  124 +
  125 +Get.putAsync<YourAsyncClass>( () async => await YourAsyncClass() )
  126 +```
  127 +
  128 +This is all options you can set when using putAsync:
  129 +```dart
  130 +Get.putAsync<S>(
  131 +
  132 + // mandatory: an async method that will be executed to instantiate your class
  133 + AsyncInstanceBuilderCallback<S> builder,
  134 +
  135 + // optional: same as Get.put(), it is used for when you want multiple different instance of a same class
  136 + // must be unique
  137 + String tag,
  138 +
  139 + // optional: same as in Get.put(), used when you need to maintain that instance alive in the entire app
  140 + // defaults to false
  141 + bool permanent = false
  142 +)
  143 +```
  144 +
  145 +### Get.create
  146 +
  147 +This one is tricky. A detailed explanation of what this is and the differences between the other one can be found on [Differences between methods:](#differences-between-methods) section
  148 +
  149 +```dart
  150 +Get.Create<SomeClass>(() => SomeClass());
  151 +Get.Create<LoginController>(() => LoginController());
  152 +```
  153 +
  154 +This is all options you can set when using create:
  155 +
  156 +```dart
  157 +Get.create<S>(
  158 + // required: a function that returns a class that will be "fabricated" every
  159 + // time `Get.find()` is called
  160 + // Example: Get.create<YourClass>(() => YourClass())
  161 + FcBuilderFunc<S> builder,
  162 +
  163 + // optional: just like Get.put(), but it is used when you need multiple instances
  164 + // of a of a same class
  165 + // Useful in case you have a list that each item need it's own controller
  166 + // needs to be a unique string. Just change from tag to name
  167 + String name,
  168 +
  169 + // optional: just like int`Get.put()`, it is for when you need to keep the
  170 + // instance alive thoughout the entire app. The difference is in Get.create
  171 + // permanent is true by default
  172 + bool permanent = true
  173 +```
  174 +
  175 +## Using instantiated methods/classes
  176 +
  177 +Imagine that you have navigated through numerous routes, and you need a data that was left behind in your controller, you would need a state manager combined with the Provider or Get_it, correct? Not with Get. You just need to ask Get to "find" for your controller, you don't need any additional dependencies:
  178 +
  179 +```dart
  180 +final controller = Get.find<Controller>();
  181 +// OR
  182 +Controller controller = Get.find();
  183 +
  184 +// Yes, it looks like Magic, Get will find your controller, and will deliver it to you.
  185 +// You can have 1 million controllers instantiated, Get will always give you the right controller.
  186 +```
  187 +
  188 +And then you will be able to recover your controller data that was obtained back there:
  189 +
  190 +```dart
  191 +Text(controller.textFromApi);
  192 +```
  193 +
  194 +Since the returned value is a normal class, you can do anything you want:
  195 +```dart
  196 +int count = Get.find<SharedPreferences>().getInt('counter');
  197 +print(count); // out: 12345
  198 +```
  199 +
  200 +To remove an instance of Get:
  201 +
  202 +```dart
  203 +Get.delete<Controller>(); //usually you don't need to do this because GetX already delete unused controllers
  204 +```
  205 +
  206 +## Specifying an alternate instance
  207 +
  208 +A currently inserted instance can be replaced with a similar or extended class instance by using the `replace` or `lazyReplace` method. This can then be retrieved by using the original class.
  209 +
  210 +```dart
  211 +abstract class BaseClass {}
  212 +class ParentClass extends BaseClass {}
  213 +
  214 +class ChildClass extends ParentClass {
  215 + bool isChild = true;
  216 +}
  217 +
  218 +
  219 +Get.put<BaseClass>(ParentClass());
  220 +
  221 +Get.replace<BaseClass>(ChildClass());
  222 +
  223 +final instance = Get.find<BaseClass>();
  224 +print(instance is ChildClass); //true
  225 +
  226 +
  227 +class OtherClass extends BaseClass {}
  228 +Get.lazyReplace<BaseClass>(() => OtherClass());
  229 +
  230 +final instance = Get.find<BaseClass>();
  231 +print(instance is ChildClass); // false
  232 +print(instance is OtherClass); //true
  233 +```
  234 +
  235 +## Differences between methods
  236 +
  237 +First, let's of the `fenix` of Get.lazyPut and the `permanent` of the other methods.
  238 +
  239 +The fundamental difference between `permanent` and `fenix` is how you want to store your instances.
  240 +
  241 +Reinforcing: by default, GetX deletes instances when they are not in use.
  242 +It means that: If screen 1 has controller 1 and screen 2 has controller 2 and you remove the first route from stack, (like if you use `Get.off()` or `Get.offNamed()`) the controller 1 lost its use so it will be erased.
  243 +
  244 +But if you want to opt for using `permanent:true`, then the controller will not be lost in this transition - which is very useful for services that you want to keep alive throughout the entire application.
  245 +
  246 +`fenix` in the other hand is for services that you don't worry in losing between screen changes, but when you need that service, you expect that it is alive. So basically, it will dispose the unused controller/service/class, but when you need it, it will "recreate from the ashes" a new instance.
  247 +
  248 +Proceeding with the differences between methods:
  249 +
  250 +- Get.put and Get.putAsync follows the same creation order, with the difference that the second uses an asynchronous method: those two methods creates and initializes the instance. That one is inserted directly in the memory, using the internal method `insert` with the parameters `permanent: false` and `isSingleton: true` (this isSingleton parameter only purpose is to tell if it is to use the dependency on `dependency` or if it is to use the dependency on `FcBuilderFunc`). After that, `Get.find()` is called that immediately initialize the instances that are on memory.
  251 +
  252 +- Get.create: As the name implies, it will "create" your dependency! Similar to `Get.put()`, it also calls the internal method `insert` to instancing. But `permanent` became true and `isSingleton` became false (since we are "creating" our dependency, there is no way for it to be a singleton instace, that's why is false). And because it has `permanent: true`, we have by default the benefit of not losing it between screens! Also, `Get.find()` is not called immediately, it wait to be used in the screen to be called. It is created this way to make use of the parameter `permanent`, since then, worth noticing, `Get.create()` was made with the goal of create not shared instances, but don't get disposed, like for example a button in a listView, that you want a unique instance for that list - because of that, Get.create must be used together with GetWidget.
  253 +
  254 +- Get.lazyPut: As the name implies, it is a lazy proccess. The instance is create, but it is not called to be used immediately, it remains waiting to be called. Contrary to the other methods, `insert` is not called here. Instead, the instance is inserted in another part of the memory, a part responsible to tell if the instance can be recreated or not, let's call it "factory". If we want to create something to be used later, it will not be mix with things been used right now. And here is where `fenix` magic enters: if you opt to leaving `fenix: false`, and your `smartManagement` are not `keepFactory`, then when using `Get.find` the instance will change the place in the memory from the "factory" to common instance memory area. Right after that, by default it is removed from the "factory". Now, if you opt for `fenix: true`, the instance continues to exist in this dedicated part, even going to the common area, to be called again in the future.
  255 +
  256 +## Bindings
  257 +
  258 +One of the great differentials of this package, perhaps, is the possibility of full integration of the routes, state manager and dependency manager.
  259 +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.
  260 +In version 2.10 Get completely implemented the Bindings API.
  261 +Now you no longer need to use the init method. You don't even have to type your controllers if you don't want to. You can start your controllers and services in the appropriate place for that.
  262 +The Binding class is a class that will decouple dependency injection, while "binding" routes to the state manager and dependency manager.
  263 +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.
  264 +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.
  265 +
  266 +### Bindings class
  267 +
  268 +- Create a class and implements Binding
  269 +
  270 +```dart
  271 +class HomeBinding implements Bindings {}
  272 +```
  273 +
  274 +Your IDE will automatically ask you to override the "dependencies" method, and you just need to click on the lamp, override the method, and insert all the classes you are going to use on that route:
  275 +
  276 +```dart
  277 +class HomeBinding implements Bindings {
  278 + @override
  279 + void dependencies() {
  280 + Get.lazyPut<HomeController>(() => HomeController());
  281 + Get.put<Service>(()=> Api());
  282 + }
  283 +}
  284 +
  285 +class DetailsBinding implements Bindings {
  286 + @override
  287 + void dependencies() {
  288 + Get.lazyPut<DetailsController>(() => DetailsController());
  289 + }
  290 +}
  291 +```
  292 +
  293 +Now you just need to inform your route, that you will use that binding to make the connection between route manager, dependencies and states.
  294 +
  295 +- Using named routes:
  296 +
  297 +```dart
  298 +getPages: [
  299 + GetPage(
  300 + name: '/',
  301 + page: () => HomeView(),
  302 + binding: HomeBinding(),
  303 + ),
  304 + GetPage(
  305 + name: '/details',
  306 + page: () => DetailsView(),
  307 + binding: DetailsBinding(),
  308 + ),
  309 +];
  310 +```
  311 +
  312 +- Using normal routes:
  313 +
  314 +```dart
  315 +Get.to(Home(), binding: HomeBinding());
  316 +Get.to(DetailsView(), binding: DetailsBinding())
  317 +```
  318 +
  319 +There, you don't have to worry about memory management of your application anymore, Get will do it for you.
  320 +
  321 +The Binding class is called when a route is called, you can create an "initialBinding in your GetMaterialApp to insert all the dependencies that will be created.
  322 +
  323 +```dart
  324 +GetMaterialApp(
  325 + initialBinding: SampleBind(),
  326 + home: Home(),
  327 +);
  328 +```
  329 +
  330 +### BindingsBuilder
  331 +
  332 +The default way of creating a binding is by creating a class that implements Bindings.
  333 +But alternatively, you can use `BindingsBuilder` callback so that you can simply use a function to instantiate whatever you desire.
  334 +
  335 +Example:
  336 +
  337 +```dart
  338 +getPages: [
  339 + GetPage(
  340 + name: '/',
  341 + page: () => HomeView(),
  342 + binding: BindingsBuilder(() {
  343 + Get.lazyPut<ControllerX>(() => ControllerX());
  344 + Get.put<Service>(()=> Api());
  345 + }),
  346 + ),
  347 + GetPage(
  348 + name: '/details',
  349 + page: () => DetailsView(),
  350 + binding: BindingsBuilder(() {
  351 + Get.lazyPut<DetailsController>(() => DetailsController());
  352 + }),
  353 + ),
  354 +];
  355 +```
  356 +
  357 +That way you can avoid to create one Binding class for each route making this even simpler.
  358 +
  359 +Both ways of doing work perfectly fine and we want you to use what most suit your tastes.
  360 +
  361 +### SmartManagement
  362 +
  363 +GetX by default disposes unused controllers from memory, even if a failure occurs and a widget that uses it is not properly disposed.
  364 +This is what is called the `full` mode of dependency management.
  365 +But if you want to change the way GetX controls the disposal of classes, you have `SmartManagement` class that you can set different behaviors.
  366 +
  367 +#### How to change
  368 +
  369 +If you want to change this config (which you usually don't need) this is the way:
  370 +
  371 +```dart
  372 +void main () {
  373 + runApp(
  374 + GetMaterialApp(
  375 + smartManagement: SmartManagement.onlyBuilders //here
  376 + home: Home(),
  377 + )
  378 + )
  379 +}
  380 +```
  381 +
  382 +#### SmartManagement.full
  383 +
  384 +It is the default one. Dispose classes that are not being used and were not set to be permanent. In the majority of the cases you will want to keep this config untouched. If you new to GetX then don't change this.
  385 +
  386 +#### SmartManagement.onlyBuilders
  387 +With this option, only controllers started in `init:` or loaded into a Binding with `Get.lazyPut()` will be disposed.
  388 +
  389 +If you use `Get.put()` or `Get.putAsync()` or any other approach, SmartManagement will not have permissions to exclude this dependency.
  390 +
  391 +With the default behavior, even widgets instantiated with "Get.put" will be removed, unlike SmartManagement.onlyBuilders.
  392 +
  393 +#### SmartManagement.keepFactory
  394 +
  395 +Just like SmartManagement.full, it will remove it's dependencies when it's not being used anymore. However, it will keep their factory, which means it will recreate the dependency if you need that instance again.
  396 +
  397 +### How bindings work under the hood
  398 +Bindings creates transitory factories, which are created the moment you click to go to another screen, and will be destroyed as soon as the screen-changing animation happens.
  399 +This happens so fast that the analyzer will not even be able to register it.
  400 +When you navigate to this screen again, a new temporary factory will be called, so this is preferable to using SmartManagement.keepFactory, but if you don't want to create Bindings, or want to keep all your dependencies on the same Binding, it will certainly help you.
  401 +Factories take up little memory, they don't hold instances, but a function with the "shape" of that class you want.
  402 +This has a very low cost in memory, but since the purpose of this lib is to get the maximum performance possible using the minimum resources, Get removes even the factories by default.
  403 +Use whichever is most convenient for you.
  404 +
  405 +## Notes
  406 +
  407 +- DO NOT USE SmartManagement.keepFactory if you are using multiple Bindings. It was designed to be used without Bindings, or with a single Binding linked in the GetMaterialApp's initialBinding.
  408 +
  409 +- Using Bindings is completely optional, if you want you can use `Get.put()` and `Get.find()` on classes that use a given controller without any problem.
  410 +However, if you work with Services or any other abstraction, I recommend using Bindings for a better organization.
  1 +- [Route Management](#route-management)
  2 + - [How to use](#how-to-use)
  3 + - [Navigation without named routes](#navigation-without-named-routes)
  4 + - [Navigation with named routes](#navigation-with-named-routes)
  5 + - [Send data to named Routes](#send-data-to-named-routes)
  6 + - [Dynamic urls links](#dynamic-urls-links)
  7 + - [Middleware](#middleware)
  8 + - [Navigation without context](#navigation-without-context)
  9 + - [SnackBars](#snackbars)
  10 + - [Dialogs](#dialogs)
  11 + - [BottomSheets](#bottomsheets)
  12 + - [Nested Navigation](#nested-navigation)
  13 +
  14 +# Route Management
  15 +
  16 +This is the complete explanation of all there is to Getx when the matter is route management.
  17 +
  18 +## How to use
  19 +
  20 +Add this to your pubspec.yaml file:
  21 +
  22 +```yaml
  23 +dependencies:
  24 + get:
  25 +```
  26 +
  27 +If you are going to use routes/snackbars/dialogs/bottomsheets without context, or use the high-level Get APIs, you need to simply add "Get" before your MaterialApp, turning it into GetMaterialApp and enjoy!
  28 +
  29 +```dart
  30 +GetMaterialApp( // Before: MaterialApp(
  31 + home: MyHome(),
  32 +)
  33 +```
  34 +
  35 +## Navigation without named routes
  36 +
  37 +To navigate to a new screen:
  38 +
  39 +```dart
  40 +Get.to(NextScreen());
  41 +```
  42 +
  43 +To close snackbars, dialogs, bottomsheets, or anything you would normally close with Navigator.pop(context);
  44 +
  45 +```dart
  46 +Get.back();
  47 +```
  48 +
  49 +To go to the next screen and no option to go back to the previous screen (for use in SplashScreens, login screens and etc.)
  50 +
  51 +```dart
  52 +Get.off(NextScreen());
  53 +```
  54 +
  55 +To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)
  56 +
  57 +```dart
  58 +Get.offAll(NextScreen());
  59 +```
  60 +
  61 +To navigate to the next route, and receive or update data as soon as you return from it:
  62 +
  63 +```dart
  64 +var data = await Get.to(Payment());
  65 +```
  66 +
  67 +on other screen, send a data for previous route:
  68 +
  69 +```dart
  70 +Get.back(result: 'success');
  71 +```
  72 +
  73 +And use it:
  74 +
  75 +ex:
  76 +
  77 +```dart
  78 +if(data == 'success') madeAnything();
  79 +```
  80 +
  81 +Don't you want to learn our syntax?
  82 +Just change the Navigator (uppercase) to navigator (lowercase), and you will have all the functions of the standard navigation, without having to use context
  83 +Example:
  84 +
  85 +```dart
  86 +
  87 +// Default Flutter navigator
  88 +Navigator.of(context).push(
  89 + context,
  90 + MaterialPageRoute(
  91 + builder: (BuildContext context) {
  92 + return HomePage();
  93 + },
  94 + ),
  95 +);
  96 +
  97 +// Get using Flutter syntax without needing context
  98 +navigator.push(
  99 + MaterialPageRoute(
  100 + builder: (_) {
  101 + return HomePage();
  102 + },
  103 + ),
  104 +);
  105 +
  106 +// Get syntax (It is much better, but you have the right to disagree)
  107 +Get.to(HomePage());
  108 +
  109 +
  110 +```
  111 +
  112 +## Navigation with named routes
  113 +
  114 +- If you prefer to navigate by namedRoutes, Get also supports this.
  115 +
  116 +To navigate to nextScreen
  117 +
  118 +```dart
  119 +Get.toNamed("/NextScreen");
  120 +```
  121 +
  122 +To navigate and remove the previous screen from the tree.
  123 +
  124 +```dart
  125 +Get.offNamed("/NextScreen");
  126 +```
  127 +
  128 +To navigate and remove all previous screens from the tree.
  129 +
  130 +```dart
  131 +Get.offAllNamed("/NextScreen");
  132 +```
  133 +
  134 +To define routes, use GetMaterialApp:
  135 +
  136 +```dart
  137 +void main() {
  138 + runApp(
  139 + GetMaterialApp(
  140 + initialRoute: '/',
  141 + getPages: [
  142 + GetPage(name: '/', page: () => MyHomePage()),
  143 + GetPage(name: '/second', page: () => Second()),
  144 + GetPage(
  145 + name: '/third',
  146 + page: () => Third(),
  147 + transition: Transition.zoom
  148 + ),
  149 + ],
  150 + )
  151 + );
  152 +}
  153 +```
  154 +
  155 +To handle navigation to non-defined routes (404 error), you can define an unknownRoute page in GetMaterialApp.
  156 +
  157 +```dart
  158 +void main() {
  159 + runApp(
  160 + GetMaterialApp(
  161 + unknownRoute: GetPage(name: '/notfound', page: () => UnknownRoutePage()),
  162 + initialRoute: '/',
  163 + getPages: [
  164 + GetPage(name: '/', page: () => MyHomePage()),
  165 + GetPage(name: '/second', page: () => Second()),
  166 + ],
  167 + )
  168 + );
  169 +}
  170 +```
  171 +
  172 +### Send data to named Routes
  173 +
  174 +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.
  175 +
  176 +```dart
  177 +Get.toNamed("/NextScreen", arguments: 'Get is the best');
  178 +```
  179 +
  180 +on your class or controller:
  181 +
  182 +```dart
  183 +print(Get.arguments);
  184 +//print out: Get is the best
  185 +```
  186 +
  187 +### Dynamic urls links
  188 +
  189 +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.
  190 +
  191 +```dart
  192 +Get.offAllNamed("/NextScreen?device=phone&id=354&name=Enzo");
  193 +```
  194 +
  195 +on your controller/bloc/stateful/stateless class:
  196 +
  197 +```dart
  198 +print(Get.parameters['id']);
  199 +// out: 354
  200 +print(Get.parameters['name']);
  201 +// out: Enzo
  202 +```
  203 +
  204 +You can also receive NamedParameters with Get easily:
  205 +
  206 +```dart
  207 +void main() {
  208 + runApp(
  209 + GetMaterialApp(
  210 + initialRoute: '/',
  211 + getPages: [
  212 + GetPage(
  213 + name: '/',
  214 + page: () => MyHomePage(),
  215 + ),
  216 + GetPage(
  217 + name: '/profile/',
  218 + page: () => MyProfile(),
  219 + ),
  220 + //You can define a different page for routes with arguments, and another without arguments, but for that you must use the slash '/' on the route that will not receive arguments as above.
  221 + GetPage(
  222 + name: '/profile/:user',
  223 + page: () => UserProfile(),
  224 + ),
  225 + GetPage(
  226 + name: '/third',
  227 + page: () => Third(),
  228 + transition: Transition.cupertino
  229 + ),
  230 + ],
  231 + )
  232 + );
  233 +}
  234 +```
  235 +
  236 +Send data on route name
  237 +
  238 +```dart
  239 +Get.toNamed("/profile/34954");
  240 +```
  241 +
  242 +On second screen take the data by parameter
  243 +
  244 +```dart
  245 +print(Get.parameters['user']);
  246 +// out: 34954
  247 +```
  248 +
  249 +or send multiple parameters like this
  250 +
  251 +```dart
  252 +Get.toNamed("/profile/34954?flag=true&country=italy");
  253 +```
  254 +or
  255 +```dart
  256 +var parameters = <String, String>{"flag": "true","country": "italy",};
  257 +Get.toNamed("/profile/34954", parameters: parameters);
  258 +```
  259 +
  260 +On second screen take the data by parameters as usually
  261 +
  262 +```dart
  263 +print(Get.parameters['user']);
  264 +print(Get.parameters['flag']);
  265 +print(Get.parameters['country']);
  266 +// out: 34954 true italy
  267 +```
  268 +
  269 +
  270 +
  271 +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
  272 +
  273 +### Middleware
  274 +
  275 +If you want to listen Get events to trigger actions, you can to use routingCallback to it
  276 +
  277 +```dart
  278 +GetMaterialApp(
  279 + routingCallback: (routing) {
  280 + if(routing.current == '/second'){
  281 + openAds();
  282 + }
  283 + }
  284 +)
  285 +```
  286 +
  287 +If you are not using GetMaterialApp, you can use the manual API to attach Middleware observer.
  288 +
  289 +```dart
  290 +void main() {
  291 + runApp(
  292 + MaterialApp(
  293 + onGenerateRoute: Router.generateRoute,
  294 + initialRoute: "/",
  295 + navigatorKey: Get.key,
  296 + navigatorObservers: [
  297 + GetObserver(MiddleWare.observer), // HERE !!!
  298 + ],
  299 + ),
  300 + );
  301 +}
  302 +```
  303 +
  304 +Create a MiddleWare class
  305 +
  306 +```dart
  307 +class MiddleWare {
  308 + static observer(Routing routing) {
  309 + /// You can listen in addition to the routes, the snackbars, dialogs and bottomsheets on each screen.
  310 + ///If you need to enter any of these 3 events directly here,
  311 + ///you must specify that the event is != Than you are trying to do.
  312 + if (routing.current == '/second' && !routing.isSnackbar) {
  313 + Get.snackbar("Hi", "You are on second route");
  314 + } else if (routing.current =='/third'){
  315 + print('last route called');
  316 + }
  317 + }
  318 +}
  319 +```
  320 +
  321 +Now, use Get on your code:
  322 +
  323 +```dart
  324 +class First extends StatelessWidget {
  325 + @override
  326 + Widget build(BuildContext context) {
  327 + return Scaffold(
  328 + appBar: AppBar(
  329 + leading: IconButton(
  330 + icon: Icon(Icons.add),
  331 + onPressed: () {
  332 + Get.snackbar("hi", "i am a modern snackbar");
  333 + },
  334 + ),
  335 + title: Text('First Route'),
  336 + ),
  337 + body: Center(
  338 + child: ElevatedButton(
  339 + child: Text('Open route'),
  340 + onPressed: () {
  341 + Get.toNamed("/second");
  342 + },
  343 + ),
  344 + ),
  345 + );
  346 + }
  347 +}
  348 +
  349 +class Second extends StatelessWidget {
  350 + @override
  351 + Widget build(BuildContext context) {
  352 + return Scaffold(
  353 + appBar: AppBar(
  354 + leading: IconButton(
  355 + icon: Icon(Icons.add),
  356 + onPressed: () {
  357 + Get.snackbar("hi", "i am a modern snackbar");
  358 + },
  359 + ),
  360 + title: Text('second Route'),
  361 + ),
  362 + body: Center(
  363 + child: ElevatedButton(
  364 + child: Text('Open route'),
  365 + onPressed: () {
  366 + Get.toNamed("/third");
  367 + },
  368 + ),
  369 + ),
  370 + );
  371 + }
  372 +}
  373 +
  374 +class Third extends StatelessWidget {
  375 + @override
  376 + Widget build(BuildContext context) {
  377 + return Scaffold(
  378 + appBar: AppBar(
  379 + title: Text("Third Route"),
  380 + ),
  381 + body: Center(
  382 + child: ElevatedButton(
  383 + onPressed: () {
  384 + Get.back();
  385 + },
  386 + child: Text('Go back!'),
  387 + ),
  388 + ),
  389 + );
  390 + }
  391 +}
  392 +```
  393 +
  394 +## Navigation without context
  395 +
  396 +### SnackBars
  397 +
  398 +To have a simple SnackBar with Flutter, you must get the context of Scaffold, or you must use a GlobalKey attached to your Scaffold
  399 +
  400 +```dart
  401 +final snackBar = SnackBar(
  402 + content: Text('Hi!'),
  403 + action: SnackBarAction(
  404 + label: 'I am a old and ugly snackbar :(',
  405 + onPressed: (){}
  406 + ),
  407 +);
  408 +// Find the Scaffold in the widget tree and use
  409 +// it to show a SnackBar.
  410 +Scaffold.of(context).showSnackBar(snackBar);
  411 +```
  412 +
  413 +With Get:
  414 +
  415 +```dart
  416 +Get.snackbar('Hi', 'i am a modern snackbar');
  417 +```
  418 +
  419 +With Get, all you have to do is call your Get.snackbar from anywhere in your code or customize it however you want!
  420 +
  421 +```dart
  422 +Get.snackbar(
  423 + "Hey i'm a Get SnackBar!", // title
  424 + "It's unbelievable! I'm using SnackBar without context, without boilerplate, without Scaffold, it is something truly amazing!", // message
  425 + icon: Icon(Icons.alarm),
  426 + shouldIconPulse: true,
  427 + onTap:(){},
  428 + barBlur: 20,
  429 + isDismissible: true,
  430 + duration: Duration(seconds: 3),
  431 +);
  432 +
  433 +
  434 + ////////// ALL FEATURES //////////
  435 + // Color colorText,
  436 + // Duration duration,
  437 + // SnackPosition snackPosition,
  438 + // Widget titleText,
  439 + // Widget messageText,
  440 + // bool instantInit,
  441 + // Widget icon,
  442 + // bool shouldIconPulse,
  443 + // double maxWidth,
  444 + // EdgeInsets margin,
  445 + // EdgeInsets padding,
  446 + // double borderRadius,
  447 + // Color borderColor,
  448 + // double borderWidth,
  449 + // Color backgroundColor,
  450 + // Color leftBarIndicatorColor,
  451 + // List<BoxShadow> boxShadows,
  452 + // Gradient backgroundGradient,
  453 + // TextButton mainButton,
  454 + // OnTap onTap,
  455 + // bool isDismissible,
  456 + // bool showProgressIndicator,
  457 + // AnimationController progressIndicatorController,
  458 + // Color progressIndicatorBackgroundColor,
  459 + // Animation<Color> progressIndicatorValueColor,
  460 + // SnackStyle snackStyle,
  461 + // Curve forwardAnimationCurve,
  462 + // Curve reverseAnimationCurve,
  463 + // Duration animationDuration,
  464 + // double barBlur,
  465 + // double overlayBlur,
  466 + // Color overlayColor,
  467 + // Form userInputForm
  468 + ///////////////////////////////////
  469 +```
  470 +
  471 +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
  472 +`Get.rawSnackbar();` which provides the RAW API on which Get.snackbar was built.
  473 +
  474 +### Dialogs
  475 +
  476 +To open dialog:
  477 +
  478 +```dart
  479 +Get.dialog(YourDialogWidget());
  480 +```
  481 +
  482 +To open default dialog:
  483 +
  484 +```dart
  485 +Get.defaultDialog(
  486 + onConfirm: () => print("Ok"),
  487 + middleText: "Dialog made in 3 lines of code"
  488 +);
  489 +```
  490 +
  491 +You can also use Get.generalDialog instead of showGeneralDialog.
  492 +
  493 +For all other Flutter dialog widgets, including cupertinos, you can use Get.overlayContext instead of context, and open it anywhere in your code.
  494 +For widgets that don't use Overlay, you can use Get.context.
  495 +These two contexts will work in 99% of cases to replace the context of your UI, except for cases where inheritedWidget is used without a navigation context.
  496 +
  497 +### BottomSheets
  498 +
  499 +Get.bottomSheet is like showModalBottomSheet, but don't need of context.
  500 +
  501 +```dart
  502 +Get.bottomSheet(
  503 + Container(
  504 + child: Wrap(
  505 + children: <Widget>[
  506 + ListTile(
  507 + leading: Icon(Icons.music_note),
  508 + title: Text('Music'),
  509 + onTap: () {}
  510 + ),
  511 + ListTile(
  512 + leading: Icon(Icons.videocam),
  513 + title: Text('Video'),
  514 + onTap: () {},
  515 + ),
  516 + ],
  517 + ),
  518 + )
  519 +);
  520 +```
  521 +
  522 +## Nested Navigation
  523 +
  524 +Get made Flutter's nested navigation even easier.
  525 +You don't need the context, and you will find your navigation stack by Id.
  526 +
  527 +- 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.
  528 +
  529 +See how simple it is:
  530 +
  531 +```dart
  532 +Navigator(
  533 + key: Get.nestedKey(1), // create a key by index
  534 + initialRoute: '/',
  535 + onGenerateRoute: (settings) {
  536 + if (settings.name == '/') {
  537 + return GetPageRoute(
  538 + page: () => Scaffold(
  539 + appBar: AppBar(
  540 + title: Text("Main"),
  541 + ),
  542 + body: Center(
  543 + child: TextButton(
  544 + color: Colors.blue,
  545 + onPressed: () {
  546 + Get.toNamed('/second', id:1); // navigate by your nested route by index
  547 + },
  548 + child: Text("Go to second"),
  549 + ),
  550 + ),
  551 + ),
  552 + );
  553 + } else if (settings.name == '/second') {
  554 + return GetPageRoute(
  555 + page: () => Center(
  556 + child: Scaffold(
  557 + appBar: AppBar(
  558 + title: Text("Main"),
  559 + ),
  560 + body: Center(
  561 + child: Text("second")
  562 + ),
  563 + ),
  564 + ),
  565 + );
  566 + }
  567 + }
  568 +),
  569 +```
  1 +* [State Management](#state-management)
  2 + + [Reactive State Manager](#reactive-state-manager)
  3 + - [Advantages](#advantages)
  4 + - [Maximum performance:](#maximum-performance)
  5 + - [Declaring a reactive variable](#declaring-a-reactive-variable)
  6 + - [Having a reactive state, is easy.](#having-a-reactive-state-is-easy)
  7 + - [Using the values in the view](#using-the-values-in-the-view)
  8 + - [Conditions to rebuild](#conditions-to-rebuild)
  9 + - [Where .obs can be used](#where-obs-can-be-used)
  10 + - [Note about Lists](#note-about-lists)
  11 + - [Why i have to use .value](#why-i-have-to-use-value)
  12 + - [Obx()](#obx)
  13 + - [Workers](#workers)
  14 + + [Simple State Manager](#simple-state-manager)
  15 + - [Advantages](#advantages-1)
  16 + - [Usage](#usage)
  17 + - [How it handles controllers](#how-it-handles-controllers)
  18 + - [You won't need StatefulWidgets anymore](#you-wont-need-statefulwidgets-anymore)
  19 + - [Why it exists](#why-it-exists)
  20 + - [Other ways of using it](#other-ways-of-using-it)
  21 + - [Unique IDs](#unique-ids)
  22 + + [Mixing the two state managers](#mixing-the-two-state-managers)
  23 + + [GetBuilder vs GetX vs Obx vs MixinBuilder](#getbuilder-vs-getx-vs-obx-vs-mixinbuilder)
  24 +
  25 +# State Management
  26 +
  27 +GetX does not use Streams or ChangeNotifier like other state managers. Why? In addition to building applications for android, iOS, web, linux, macos and linux, with GetX you can build server applications with the same syntax as Flutter/GetX. In order to improve response time and reduce RAM consumption, we created GetValue and GetStream, which are low latency solutions that deliver a lot of performance, at a low operating cost. We use this base to build all of our resources, including state management.
  28 +
  29 +* _Complexity_: Some state managers are complex and have a lot of boilerplate. With GetX you don't have to define a class for each event, the code is highly clean and clear, and you do a lot more by writing less. Many people have given up on Flutter because of this topic, and they now finally have a stupidly simple solution for managing states.
  30 +* _No code generators_: You spend half your development time writing your application logic. Some state managers rely on code generators to have minimally readable code. Changing a variable and having to run build_runner can be unproductive, and often the waiting time after a flutter clean will be long, and you will have to drink a lot of coffee.
  31 +
  32 +With GetX everything is reactive, and nothing depends on code generators, increasing your productivity in all aspects of your development.
  33 +
  34 +* _It does not depend on context_: You probably already needed to send the context of your view to a controller, making the View's coupling with your business logic high. You have probably had to use a dependency for a place that has no context, and had to pass the context through various classes and functions. This just doesn't exist with GetX. You have access to your controllers from within your controllers without any context. You don't need to send the context by parameter for literally nothing.
  35 +* _Granular control_: most state managers are based on ChangeNotifier. ChangeNotifier will notify all widgets that depend on it when notifyListeners is called. If you have 40 widgets on one screen, which have a variable of your ChangeNotifier class, when you update one, all of them will be rebuilt.
  36 +
  37 +With GetX, even nested widgets are respected. If you have Obx watching your ListView, and another watching a checkbox inside the ListView, when changing the CheckBox value, only it will be updated, when changing the List value, only the ListView will be updated.
  38 +
  39 +* _It only reconstructs if its variable REALLY changes_: GetX has flow control, that means if you display a Text with 'Paola', if you change the observable variable to 'Paola' again, the widget will not be reconstructed. That's because GetX knows that 'Paola' is already being displayed in Text, and will not do unnecessary reconstructions.
  40 +
  41 +Most (if not all) current state managers will rebuild on the screen.
  42 +
  43 +## Reactive State Manager
  44 +
  45 +Reactive programming can alienate many people because it is said to be complicated. GetX turns reactive programming into something quite simple:
  46 +
  47 +* You won't need to create StreamControllers.
  48 +* You won't need to create a StreamBuilder for each variable
  49 +* You will not need to create a class for each state.
  50 +* You will not need to create a get for an initial value.
  51 +
  52 +Reactive programming with Get is as easy as using setState.
  53 +
  54 +Let's imagine that you have a name variable and want that every time you change it, all widgets that use it are automatically changed.
  55 +
  56 +This is your count variable:
  57 +
  58 +``` dart
  59 +var name = 'Jonatas Borges';
  60 +```
  61 +
  62 +To make it observable, you just need to add ".obs" to the end of it:
  63 +
  64 +``` dart
  65 +var name = 'Jonatas Borges'.obs;
  66 +```
  67 +
  68 +That's all. It's *that* simple.
  69 +
  70 +From now on, we might refer to this reactive-".obs"(ervables) variables as _Rx_.
  71 +
  72 +What did we do under the hood? We created a `Stream` of `String` s, assigned the initial value `"Jonatas Borges"` , we notified all widgets that use `"Jonatas Borges"` that they now "belong" to this variable, and when the _Rx_ value changes, they will have to change as well.
  73 +
  74 +This is the **magic of GetX**, thanks to Dart's capabilities.
  75 +
  76 +But, as we know, a `Widget` can only be changed if it is inside a function, because static classes do not have the power to "auto-change".
  77 +
  78 +You will need to create a `StreamBuilder` , subscribe to this variable to listen for changes, and create a "cascade" of nested `StreamBuilder` if you want to change several variables in the same scope, right?
  79 +
  80 +No, you don't need a `StreamBuilder` , but you are right about static classes.
  81 +
  82 +Well, in the view, we usually have a lot of boilerplate when we want to change a specific Widget, that's the Flutter way.
  83 +With **GetX** you can also forget about this boilerplate code.
  84 +
  85 +`StreamBuilder( … )` ? `initialValue: …` ? `builder: …` ? Nope, you just need to place this variable inside an `Obx()` Widget.
  86 +
  87 +``` dart
  88 +Obx (() => Text (controller.name));
  89 +```
  90 +
  91 +_What do you need to memorize?_ Only `Obx(() =>` .
  92 +
  93 +You are just passing that Widget through an arrow-function into an `Obx()` (the "Observer" of the _Rx_).
  94 +
  95 +`Obx` is pretty smart, and will only change if the value of `controller.name` changes.
  96 +
  97 +If `name` is `"John"` , and you change it to `"John"` ( `name.value = "John"` ), as it's the same `value` as before, nothing will change on the screen, and `Obx` , to save resources, will simply ignore the new value and not rebuild the Widget. **Isn't that amazing?**
  98 +
  99 +> So, what if I have 5 _Rx_ (observable) variables within an `Obx` ?
  100 +
  101 +It will just update when **any** of them changes.
  102 +
  103 +> And if I have 30 variables in a class, when I update one, will it update **all** the variables that are in that class?
  104 +
  105 +Nope, just the **specific Widget** that uses that _Rx_ variable.
  106 +
  107 +So, **GetX** only updates the screen, when the _Rx_ variable changes it's value.
  108 +
  109 +```
  110 +
  111 +final isOpen = false.obs;
  112 +
  113 +// NOTHING will happen... same value.
  114 +void onButtonTap() => isOpen.value=false;
  115 +```
  116 +
  117 +### Advantages
  118 +
  119 +**GetX()** helps you when you need **granular** control over what's being updated.
  120 +
  121 +If you do not need `unique IDs` , because all your variables will be modified when you perform an action, then use `GetBuilder` ,
  122 +because it's a Simple State Updater (in blocks, like `setState()` ), made in just a few lines of code.
  123 +It was made simple, to have the least CPU impact, and just to fulfill a single purpose (a _State_ rebuild) and spend the minimum resources possible.
  124 +
  125 +If you need a **powerful** State Manager, you can't go wrong with **GetX**.
  126 +
  127 +It doesn't work with variables, but __flows__, everything in it are `Streams` under the hood.
  128 +
  129 +You can use _rxDart_ in conjunction with it, because everything are `Streams`,
  130 +you can listen to the `event` of each "_Rx_ variable",
  131 +because everything in it are `Streams`.
  132 +
  133 +It is literally a _BLoC_ approach, easier than _MobX_, and without code generators or decorations.
  134 +You can turn **anything** into an _"Observable"_ with just a `.obs` .
  135 +
  136 +### Maximum performance:
  137 +
  138 +In addition to having a smart algorithm for minimal rebuilds, **GetX** uses comparators
  139 +to make sure the State has changed.
  140 +
  141 +If you experience any errors in your app, and send a duplicate change of State,
  142 +**GetX** will ensure it will not crash.
  143 +
  144 +With **GetX** the State only changes if the `value` change.
  145 +That's the main difference between **GetX**, and using _ `computed` from MobX_.
  146 +When joining two __observables__, and one changes; the listener of that _observable_ will change as well.
  147 +
  148 +With **GetX**, if you join two variables, `GetX()` (similar to `Observer()` ) will only rebuild if it implies a real change of State.
  149 +
  150 +### Declaring a reactive variable
  151 +
  152 +You have 3 ways to turn a variable into an "observable".
  153 +
  154 +1 - The first is using **`Rx{Type}`**.
  155 +
  156 +``` dart
  157 +// initial value is recommended, but not mandatory
  158 +final name = RxString('');
  159 +final isLogged = RxBool(false);
  160 +final count = RxInt(0);
  161 +final balance = RxDouble(0.0);
  162 +final items = RxList<String>([]);
  163 +final myMap = RxMap<String, int>({});
  164 +```
  165 +
  166 +2 - The second is to use **`Rx`** and use Darts Generics, `Rx<Type>`
  167 +
  168 +``` dart
  169 +final name = Rx<String>('');
  170 +final isLogged = Rx<Bool>(false);
  171 +final count = Rx<Int>(0);
  172 +final balance = Rx<Double>(0.0);
  173 +final number = Rx<Num>(0);
  174 +final items = Rx<List<String>>([]);
  175 +final myMap = Rx<Map<String, int>>({});
  176 +
  177 +// Custom classes - it can be any class, literally
  178 +final user = Rx<User>();
  179 +```
  180 +
  181 +3 - The third, more practical, easier and preferred approach, just add **`.obs`** as a property of your `value` :
  182 +
  183 +``` dart
  184 +final name = ''.obs;
  185 +final isLogged = false.obs;
  186 +final count = 0.obs;
  187 +final balance = 0.0.obs;
  188 +final number = 0.obs;
  189 +final items = <String>[].obs;
  190 +final myMap = <String, int>{}.obs;
  191 +
  192 +// Custom classes - it can be any class, literally
  193 +final user = User().obs;
  194 +```
  195 +
  196 +##### Having a reactive state, is easy.
  197 +
  198 +As we know, _Dart_ is now heading towards _null safety_.
  199 +To be prepared, from now on, you should always start your _Rx_ variables with an **initial value**.
  200 +
  201 +> Transforming a variable into an _observable_ + _initial value_ with **GetX** is the simplest, and most practical approach.
  202 +
  203 +You will literally add a " `.obs` " to the end of your variable, and **that’s it**, you’ve made it observable,
  204 +and its `.value` , well, will be the _initial value_).
  205 +
  206 +### Using the values in the view
  207 +
  208 +``` dart
  209 +// controller file
  210 +final count1 = 0.obs;
  211 +final count2 = 0.obs;
  212 +int get sum => count1.value + count2.value;
  213 +```
  214 +
  215 +``` dart
  216 +// view file
  217 +GetX<Controller>(
  218 + builder: (controller) {
  219 + print("count 1 rebuild");
  220 + return Text('${controller.count1.value}');
  221 + },
  222 +),
  223 +GetX<Controller>(
  224 + builder: (controller) {
  225 + print("count 2 rebuild");
  226 + return Text('${controller.count2.value}');
  227 + },
  228 +),
  229 +GetX<Controller>(
  230 + builder: (controller) {
  231 + print("count 3 rebuild");
  232 + return Text('${controller.sum}');
  233 + },
  234 +),
  235 +```
  236 +
  237 +If we increment `count1.value++` , it will print:
  238 +
  239 +* `count 1 rebuild`
  240 +
  241 +* `count 3 rebuild`
  242 +
  243 +because `count1` has a value of `1` , and `1 + 0 = 1` , changing the `sum` getter value.
  244 +
  245 +If we change `count2.value++` , it will print:
  246 +
  247 +* `count 2 rebuild`
  248 +
  249 +* `count 3 rebuild`
  250 +
  251 +because `count2.value` changed, and the result of the `sum` is now `2` .
  252 +
  253 +* NOTE: By default, the very first event will rebuild the widget, even if it is the same `value`.
  254 +
  255 + This behavior exists due to Boolean variables.
  256 +
  257 +Imagine you did this:
  258 +
  259 +``` dart
  260 +var isLogged = false.obs;
  261 +```
  262 +
  263 +And then, you checked if a user is "logged in" to trigger an event in `ever` .
  264 +
  265 +``` dart
  266 +@override
  267 +onInit() async {
  268 + ever(isLogged, fireRoute);
  269 + isLogged.value = await Preferences.hasToken();
  270 +}
  271 +
  272 +fireRoute(logged) {
  273 + if (logged) {
  274 + Get.off(Home());
  275 + } else {
  276 + Get.off(Login());
  277 + }
  278 +}
  279 +```
  280 +
  281 +if `hasToken` was `false` , there would be no change to `isLogged` , so `ever()` would never be called.
  282 +To avoid this type of behavior, the first change to an _observable_ will always trigger an event,
  283 +even if it contains the same `.value` .
  284 +
  285 +You can remove this behavior if you want, using:
  286 + `isLogged.firstRebuild = false;`
  287 +
  288 +### Conditions to rebuild
  289 +
  290 +In addition, Get provides refined state control. You can condition an event (such as adding an object to a list), on a certain condition.
  291 +
  292 +``` dart
  293 +// First parameter: condition, must return true or false.
  294 +// Second parameter: the new value to apply if the condition is true.
  295 +list.addIf(item < limit, item);
  296 +```
  297 +
  298 +Without decorations, without a code generator, without complications :smile:
  299 +
  300 +Do you know Flutter's counter app? Your Controller class might look like this:
  301 +
  302 +``` dart
  303 +class CountController extends GetxController {
  304 + final count = 0.obs;
  305 +}
  306 +```
  307 +
  308 +With a simple:
  309 +
  310 +``` dart
  311 +controller.count.value++
  312 +```
  313 +
  314 +You could update the counter variable in your UI, regardless of where it is stored.
  315 +
  316 +### Where .obs can be used
  317 +
  318 +You can transform anything on obs. Here are two ways of doing it:
  319 +
  320 +* You can convert your class values to obs
  321 +
  322 +``` dart
  323 +class RxUser {
  324 + final name = "Camila".obs;
  325 + final age = 18.obs;
  326 +}
  327 +```
  328 +
  329 +* or you can convert the entire class to be an observable
  330 +
  331 +``` dart
  332 +class User {
  333 + User({String name, int age});
  334 + var name;
  335 + var age;
  336 +}
  337 +
  338 +// when instantianting:
  339 +final user = User(name: "Camila", age: 18).obs;
  340 +```
  341 +
  342 +### Note about Lists
  343 +
  344 +Lists 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.
  345 +
  346 +You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that.
  347 +Unfortunaly 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.
  348 +
  349 +``` dart
  350 +// On the controller
  351 +final String title = 'User Info:'.obs
  352 +final list = List<User>().obs;
  353 +
  354 +// on the view
  355 +Text(controller.title.value), // String need to have .value in front of it
  356 +ListView.builder (
  357 + itemCount: controller.list.length // lists don't need it
  358 +)
  359 +```
  360 +
  361 +When you are making your own classes observable, there is a different way to update them:
  362 +
  363 +``` dart
  364 +// on the model file
  365 +// we are going to make the entire class observable instead of each attribute
  366 +class User() {
  367 + User({this.name = '', this.age = 0});
  368 + String name;
  369 + int age;
  370 +}
  371 +
  372 +// on the controller file
  373 +final user = User().obs;
  374 +// when you need to update the user variable:
  375 +user.update( (user) { // this parameter is the class itself that you want to update
  376 +user.name = 'Jonny';
  377 +user.age = 18;
  378 +});
  379 +// an alternative way of update the user variable:
  380 +user(User(name: 'João', age: 35));
  381 +
  382 +// on view:
  383 +Obx(()=> Text("Name ${user.value.name}: Age: ${user.value.age}"))
  384 +// you can also access the model values without the .value:
  385 +user().name; // notice that is the user variable, not the class (variable has lowercase u)
  386 +```
  387 +
  388 +You don't have to work with sets if you don't want to. you can use the "assign 'and" assignAll "api.
  389 +The "assign" api will clear your list, and add a single object that you want to start there.
  390 +The "assignAll" api will clear the existing list and add any iterable objects that you inject into it.
  391 +
  392 +### Why i have to use .value
  393 +
  394 +We could remove the obligation to use 'value' to `String` and `int` with a simple decoration and code generator, but the purpose of this library is precisely avoid external dependencies. We want to offer an environment ready for programming, involving the essentials (management of routes, dependencies and states), in a simple, lightweight and performant way, without a need of an external package.
  395 +
  396 +You can literally add 3 letters to your pubspec (get) and a colon and start programming. All solutions included by default, from route management to state management, aim at ease, productivity and performance.
  397 +
  398 +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.
  399 +
  400 +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.
  401 +
  402 +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.
  403 +
  404 +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.
  405 +
  406 +### Obx()
  407 +
  408 +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.
  409 +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.
  410 +
  411 +### Workers
  412 +
  413 +Workers will assist you, triggering specific callbacks when an event occurs.
  414 +
  415 +``` dart
  416 +/// Called every time `count1` changes.
  417 +ever(count1, (_) => print("$_ has been changed"));
  418 +
  419 +/// Called only first time the variable $_ is changed
  420 +once(count1, (_) => print("$_ was changed once"));
  421 +
  422 +/// Anti DDos - Called every time the user stops typing for 1 second, for example.
  423 +debounce(count1, (_) => print("debouce$_"), time: Duration(seconds: 1));
  424 +
  425 +/// Ignore all changes within 1 second.
  426 +interval(count1, (_) => print("interval $_"), time: Duration(seconds: 1));
  427 +```
  428 +
  429 +All workers (except `debounce` ) have a `condition` named parameter, which can be a `bool` or a callback that returns a `bool` .
  430 +This `condition` defines when the `callback` function executes.
  431 +
  432 +All workers returns a `Worker` instance, that you can use to cancel ( via `dispose()` ) the worker.
  433 +
  434 +
  435 +* **`ever`**
  436 +
  437 + is called every time the _Rx_ variable emits a new value.
  438 +
  439 +* **`everAll`**
  440 +
  441 + Much like `ever` , but it takes a `List` of _Rx_ values Called every time its variable is changed. That's it.
  442 +
  443 +* **`once`**
  444 +
  445 +'once' is called only the first time the variable has been changed.
  446 +
  447 +* **`debounce`**
  448 +
  449 +'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.
  450 +
  451 +* **`interval`**
  452 +
  453 +'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.
  454 +
  455 +* NOTE: Workers should always be used when starting a Controller or Class, so it should always be on onInit (recommended), Class constructor, or the initState of a StatefulWidget (this practice is not recommended in most cases, but it shouldn't have any side effects).
  456 +
  457 +## Simple State Manager
  458 +
  459 +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.
  460 +
  461 +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.
  462 +
  463 +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.
  464 +
  465 +### Advantages
  466 +
  467 +1. Update only the required widgets.
  468 +
  469 +2. Does not use changeNotifier, it is the state manager that uses less memory (close to 0mb).
  470 +
  471 +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.
  472 +
  473 +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.
  474 +
  475 +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.
  476 +
  477 +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.
  478 +
  479 +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).
  480 +
  481 +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.
  482 +
  483 +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.
  484 +
  485 +### Usage
  486 +
  487 +``` dart
  488 +// Create controller class and extends GetxController
  489 +class Controller extends GetxController {
  490 + int counter = 0;
  491 + void increment() {
  492 + counter++;
  493 + update(); // use update() to update counter variable on UI when increment be called
  494 + }
  495 +}
  496 +// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called
  497 +GetBuilder<Controller>(
  498 + init: Controller(), // INIT IT ONLY THE FIRST TIME
  499 + builder: (_) => Text(
  500 + '${_.counter}',
  501 + ),
  502 +)
  503 +//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.
  504 +```
  505 +
  506 +**Done!**
  507 +
  508 +* You have already learned how to manage states with Get.
  509 +
  510 +* 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.
  511 +
  512 +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):
  513 +
  514 +``` dart
  515 +class OtherClass extends StatelessWidget {
  516 + @override
  517 + Widget build(BuildContext context) {
  518 + return Scaffold(
  519 + body: Center(
  520 + child: GetBuilder<Controller>(
  521 + builder: (s) => Text('${s.counter}'),
  522 + ),
  523 + ),
  524 + );
  525 + }
  526 +
  527 +```
  528 +
  529 +If you need to use your controller in many other places, and outside of GetBuilder, just create a get in your controller and have it easily. (or use `Get.find<Controller>()` )
  530 +
  531 +``` dart
  532 +class Controller extends GetxController {
  533 +
  534 + /// You do not need that. I recommend using it just for ease of syntax.
  535 + /// with static method: Controller.to.increment();
  536 + /// with no static method: Get.find<Controller>().increment();
  537 + /// There is no difference in performance, nor any side effect of using either syntax. Only one does not need the type, and the other the IDE will autocomplete it.
  538 + static Controller get to => Get.find(); // add this line
  539 +
  540 + int counter = 0;
  541 + void increment() {
  542 + counter++;
  543 + update();
  544 + }
  545 +}
  546 +```
  547 +
  548 +And then you can access your controller directly, that way:
  549 +
  550 +``` dart
  551 +FloatingActionButton(
  552 + onPressed: () {
  553 + Controller.to.increment(),
  554 + } // This is incredibly simple!
  555 + child: Text("${Controller.to.counter}"),
  556 +),
  557 +```
  558 +
  559 +When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically.
  560 +
  561 +### How it handles controllers
  562 +
  563 +Let's say we have this:
  564 +
  565 + `Class a => Class B (has controller X) => Class C (has controller X)`
  566 +
  567 +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.
  568 +
  569 +### You won't need StatefulWidgets anymore
  570 +
  571 +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.
  572 +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!
  573 +Unless you need to use a mixin, like TickerProviderStateMixin, it will be totally unnecessary to use a StatefulWidget with Get.
  574 +
  575 +You can call all methods of a StatefulWidget directly from a GetBuilder.
  576 +If you need to call initState() or dispose() method for example, you can call them directly;
  577 +
  578 +``` dart
  579 +GetBuilder<Controller>(
  580 + initState: (_) => Controller.to.fetchApi(),
  581 + dispose: (_) => Controller.to.closeStreams(),
  582 + builder: (s) => Text('${s.username}'),
  583 +),
  584 +```
  585 +
  586 +A much better approach than this is to use the onInit() and onClose() method directly from your controller.
  587 +
  588 +``` dart
  589 +@override
  590 +void onInit() {
  591 + fetchApi();
  592 + super.onInit();
  593 +}
  594 +```
  595 +
  596 +* 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.
  597 +
  598 +### Why it exists
  599 +
  600 +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.
  601 +
  602 +So to simplify this:
  603 +You don't need to call methods in initState and send them by parameter to your controller, nor use your controller constructor for that, you have the onInit() method that is called at the right time for you to start your services.
  604 +You do not need to call the device, you have the onClose() method that will be called at the exact moment when your controller is no longer needed and will be removed from memory. That way, leave views for widgets only, refrain from any kind of business logic from it.
  605 +
  606 +Do not call a dispose method inside GetxController, 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:
  607 +
  608 +``` dart
  609 +class Controller extends GetxController {
  610 + StreamController<User> user = StreamController<User>();
  611 + StreamController<String> name = StreamController<String>();
  612 +
  613 + /// close stream = onClose method, not dispose.
  614 + @override
  615 + void onClose() {
  616 + user.close();
  617 + name.close();
  618 + super.onClose();
  619 + }
  620 +}
  621 +```
  622 +
  623 +Controller life cycle:
  624 +
  625 +* onInit() where it is created.
  626 +* onClose() where it is closed to make any changes in preparation for the delete method
  627 +* 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.
  628 +
  629 +### Other ways of using it
  630 +
  631 +You can use Controller instance directly on GetBuilder value:
  632 +
  633 +``` dart
  634 +GetBuilder<Controller>(
  635 + init: Controller(),
  636 + builder: (value) => Text(
  637 + '${value.counter}', //here
  638 + ),
  639 +),
  640 +```
  641 +
  642 +You may also need an instance of your controller outside of your GetBuilder, and you can use these approaches to achieve this:
  643 +
  644 +``` dart
  645 +class Controller extends GetxController {
  646 + static Controller get to => Get.find();
  647 +[...]
  648 +}
  649 +// on you view:
  650 +GetBuilder<Controller>(
  651 + init: Controller(), // use it only first time on each controller
  652 + builder: (_) => Text(
  653 + '${Controller.to.counter}', //here
  654 + )
  655 +),
  656 +```
  657 +
  658 +or
  659 +
  660 +``` dart
  661 +class Controller extends GetxController {
  662 + // static Controller get to => Get.find(); // with no static get
  663 +[...]
  664 +}
  665 +// on stateful/stateless class
  666 +GetBuilder<Controller>(
  667 + init: Controller(), // use it only first time on each controller
  668 + builder: (_) => Text(
  669 + '${Get.find<Controller>().counter}', //here
  670 + ),
  671 +),
  672 +```
  673 +
  674 +* You can use "non-canonical" approaches to do this. If you are using some other dependency manager, like get_it, modular, etc., and just want to deliver the controller instance, you can do this:
  675 +
  676 +``` dart
  677 +Controller controller = Controller();
  678 +[...]
  679 +GetBuilder<Controller>(
  680 + init: controller, //here
  681 + builder: (_) => Text(
  682 + '${controller.counter}', // here
  683 + ),
  684 +),
  685 +
  686 +```
  687 +
  688 +### Unique IDs
  689 +
  690 +If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs:
  691 +
  692 +``` dart
  693 +GetBuilder<Controller>(
  694 + id: 'text'
  695 + init: Controller(), // use it only first time on each controller
  696 + builder: (_) => Text(
  697 + '${Get.find<Controller>().counter}', //here
  698 + ),
  699 +),
  700 +```
  701 +
  702 +And update it this form:
  703 +
  704 +``` dart
  705 +update(['text']);
  706 +```
  707 +
  708 +You can also impose conditions for the update:
  709 +
  710 +``` dart
  711 +update(['text'], counter < 10);
  712 +```
  713 +
  714 +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).
  715 +
  716 +## Mixing the two state managers
  717 +
  718 +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.
  719 +
  720 +Extending GetxController is important, as they have life cycles, and can "start" and "end" events in their onInit() and onClose() methods. You can use any class for this, but I strongly recommend you use the GetxController class to place your variables, whether they are observable or not.
  721 +
  722 +## StateMixin
  723 +
  724 +Another way to handle your `UI` state is use the `StateMixin<T>` .
  725 +To implement it, use the `with` to add the `StateMixin<T>`
  726 +to your controller which allows a T model.
  727 +
  728 +``` dart
  729 +class Controller extends GetController with StateMixin<User>{}
  730 +```
  731 +
  732 +The `change()` method change the State whenever we want.
  733 +Just pass the data and the status in this way:
  734 +
  735 +```dart
  736 +change(data, status: RxStatus.success());
  737 +```
  738 +
  739 +RxStatus allow these status:
  740 +
  741 +``` dart
  742 +RxStatus.loading();
  743 +RxStatus.success();
  744 +RxStatus.empty();
  745 +RxStatus.error('message');
  746 +```
  747 +
  748 +To represent it in the UI, use:
  749 +
  750 +```dart
  751 +class OtherClass extends GetView<Controller> {
  752 + @override
  753 + Widget build(BuildContext context) {
  754 + return Scaffold(
  755 +
  756 + body: controller.obx(
  757 + (state)=>Text(state.name),
  758 +
  759 + // here you can put your custom loading indicator, but
  760 + // by default would be Center(child:CircularProgressIndicator())
  761 + onLoading: CustomLoadingIndicator(),
  762 + onEmpty: Text('No data found'),
  763 +
  764 + // here also you can set your own error widget, but by
  765 + // default will be an Center(child:Text(error))
  766 + onError: (error)=>Text(error),
  767 + ),
  768 + );
  769 +}
  770 +```
  771 +
  772 +## GetBuilder vs GetX vs Obx vs MixinBuilder
  773 +
  774 +In a decade working with programming I was able to learn some valuable lessons.
  775 +
  776 +My first contact with reactive programming was so "wow, this is incredible" and in fact reactive programming is incredible.
  777 +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.
  778 +
  779 +Reactive programming has a higher 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.
  780 +
  781 +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.
  782 +
  783 +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).
  784 +
  785 +However, GetBuilder is still a mechanical state manager, you need to call update() just like you would need to call Provider's notifyListeners().
  786 +
  787 +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.
  788 +
  789 +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.
1 import 'dart:developer' as developer; 1 import 'dart:developer' as developer;
2 import 'get_main.dart'; 2 import 'get_main.dart';
3 3
4 -///Voidcallback from logs 4 +///VoidCallback from logs
5 typedef LogWriterCallback = void Function(String text, {bool isError}); 5 typedef LogWriterCallback = void Function(String text, {bool isError});
6 6
7 /// default logger from GetX 7 /// default logger from GetX
@@ -55,7 +55,7 @@ class GetMaterialApp extends StatelessWidget { @@ -55,7 +55,7 @@ class GetMaterialApp extends StatelessWidget {
55 this.defaultTransition, 55 this.defaultTransition,
56 this.getPages, 56 this.getPages,
57 this.opaqueRoute, 57 this.opaqueRoute,
58 - this.enableLog, 58 + this.enableLog = kDebugMode,
59 this.logWriterCallback, 59 this.logWriterCallback,
60 this.popGesture, 60 this.popGesture,
61 this.transitionDuration, 61 this.transitionDuration,
@@ -170,7 +170,7 @@ class GetMaterialApp extends StatelessWidget { @@ -170,7 +170,7 @@ class GetMaterialApp extends StatelessWidget {
170 this.onInit, 170 this.onInit,
171 this.onReady, 171 this.onReady,
172 this.onDispose, 172 this.onDispose,
173 - this.enableLog, 173 + this.enableLog = kDebugMode,
174 this.logWriterCallback, 174 this.logWriterCallback,
175 this.popGesture, 175 this.popGesture,
176 this.smartManagement = SmartManagement.full, 176 this.smartManagement = SmartManagement.full,
@@ -298,13 +298,15 @@ class GetMaterialApp extends StatelessWidget { @@ -298,13 +298,15 @@ class GetMaterialApp extends StatelessWidget {
298 ) 298 )
299 : MaterialApp( 299 : MaterialApp(
300 key: _.unikey, 300 key: _.unikey,
301 - navigatorKey:  
302 - (navigatorKey == null ? Get.key : Get.addKey(navigatorKey!)), 301 + navigatorKey: (navigatorKey == null
  302 + ? Get.key
  303 + : Get.addKey(navigatorKey!)),
303 scaffoldMessengerKey: scaffoldMessengerKey, 304 scaffoldMessengerKey: scaffoldMessengerKey,
304 home: home, 305 home: home,
305 routes: routes ?? const <String, WidgetBuilder>{}, 306 routes: routes ?? const <String, WidgetBuilder>{},
306 initialRoute: initialRoute, 307 initialRoute: initialRoute,
307 - onGenerateRoute: (getPages != null ? generator : onGenerateRoute), 308 + onGenerateRoute:
  309 + (getPages != null ? generator : onGenerateRoute),
308 onGenerateInitialRoutes: (getPages == null || home != null) 310 onGenerateInitialRoutes: (getPages == null || home != null)
309 ? onGenerateInitialRoutes 311 ? onGenerateInitialRoutes
310 : initialRoutesGenerate, 312 : initialRoutesGenerate,
@@ -339,5 +341,6 @@ class GetMaterialApp extends StatelessWidget { @@ -339,5 +341,6 @@ class GetMaterialApp extends StatelessWidget {
339 shortcuts: shortcuts, 341 shortcuts: shortcuts,
340 scrollBehavior: scrollBehavior, 342 scrollBehavior: scrollBehavior,
341 // actions: actions, 343 // actions: actions,
342 - )); 344 + ),
  345 + );
343 } 346 }