Renat

create README on russian

  1 +![](get.png)
  2 +
  3 +_Languages: English (this file), [Brazilian Portuguese](README.pt-br.md), [Spanish](README-es.md),[Polish](README.pl.md)._
  4 +
  5 +[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
  6 +![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
  7 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
  8 +[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
  9 +[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
  10 +[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
  11 +<a href="https://github.com/Solido/awesome-flutter">
  12 +<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
  13 +</a>
  14 +<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>
  15 +
  16 +![](getx.png)
  17 +
  18 +- [About Get](#about-get)
  19 +- [Installing](#installing)
  20 +- [Counter App with GetX](#counter-app-with-getx)
  21 +- [The Three pillars](#the-three-pillars)
  22 + - [State management](#state-management)
  23 + - [Reactive State Manager](#reactive-state-manager)
  24 + - [More details about state management](#more-details-about-state-management)
  25 + - [Route management](#route-management)
  26 + - [More details about route management](#more-details-about-route-management)
  27 + - [Dependency management](#dependency-management)
  28 + - [More details about dependency management](#more-details-about-dependency-management)
  29 +- [Utils](#utils)
  30 + - [Internationalization](#internationalization)
  31 + - [Translations](#translations)
  32 + - [Using translations](#using-translations)
  33 + - [Locales](#locales)
  34 + - [Change locale](#change-locale)
  35 + - [System locale](#system-locale)
  36 + - [Change Theme](#change-theme)
  37 + - [Other Advanced APIs](#other-advanced-apis)
  38 + - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations)
  39 + - [Local State Widgets](#local-state-widgets)
  40 + - [ValueBuilder](#valuebuilder)
  41 + - [ObxValue](#obxvalue)
  42 + - [Useful tips](#useful-tips)
  43 + - [GetView](#getview)
  44 + - [GetWidget](#getwidget)
  45 + - [GetxService](#getxservice)
  46 +- [Breaking changes from 2.0](#breaking-changes-from-20)
  47 +- [Why Getx?](#why-getx)
  48 +- [Community](#community)
  49 + - [Community channels](#community-channels)
  50 + - [How to contribute](#how-to-contribute)
  51 + - [Articles and videos](#articles-and-videos)
  52 +
  53 +# About Get
  54 +
  55 +- GetX is an extra-light and powerful solution for Flutter. It combines high performance state management, intelligent dependency injection, and route management in a quick and practical way.
  56 +
  57 +- GetX has 3 basic principles, this means that this is the priority for all resources in the library
  58 +
  59 + - **PERFORMANCE:** GetX is focused on performance and minimum consumption of resources. Benchmarks are almost always not important in the real world, but if you want, there is a consumption indicator here([benchmarks](https://github.com/jonataslaw/benchmarks)), where GetX does better than other state management approaches, for example. The difference is not large, but it shows our concern not to waste its resources.
  60 + - **PRODUCTIVITY:** GetX uses an easy and pleasant syntax. No matter what you want to do, there is always an easier way with Getx. It will save hours of development, and will extract the maximum performance that your application can deliver
  61 + - **ORGANIZATION:** GetX allows the total decoupling of the View, presentation logic, business logic, dependency injection, and navigation. You do not need context to navigate between routes, so you are not dependent on the widget tree (visualization) for this. You don't need context to access your controllers / blocks through an inheritedWidget, so you completely decouple your presentation logic and business logic from your visualization layer. You do not need to inject your Controllers/Models/Blocs classes into your widget tree through multiproviders, for this GetX uses its own dependency injection feature, decoupling the DI from its view completely.
  62 + With GetX you know where to find each feature of your application, having clean code by default. This in addition to facilitating maintenance, makes the sharing of modules, something that until then in Flutter was unthinkable, something totally possible.
  63 + BLoC was a starting point for organizing code in Flutter, it separates business logic from visualization. Getx is a natural evolution of this, not only separating the business logic, but the presentation logic. Bonus injection of dependencies and routes are also decoupled, and the data layer is out of it all. You know where everything is, and all of this in an easier way than building a hello world.
  64 + GetX is the easiest, most practical and scalable way to build high-performance applications with the Flutter SDK, with a large ecosystem around it that works perfectly together, being easy for beginners, and accurate for experts. It is secure, stable, up-to-date, and offers a huge range of APIs build-in that are not present on default Flutter SDK.
  65 +
  66 +- GetX is not a bloated. It has a multitude of features that allow you to start programming without worrying about anything, but each of these features are in separate containers, and are only started after use. If you only use State Management, only State Management will be compiled. If you only use routes, nothing from the state management will be compiled. You can compile the benchmark repository, and you will see that using only Get state management, the application compiled with Get has become smaller than all other applications that have only the state management of other packages, because nothing that is not used will be compiled into your code, and each GetX solution was designed to be extra lightweight. The merit here also comes from Flutter's tree shaking which is incredible, and manages to eliminate unused resources like no other framework does.
  67 +
  68 +- Getx has a huge ecosystem, capable of running with the same code on Android, iOS, Web, Mac, Linux, Windows, and on your server.
  69 +**It is possible to fully reuse your code made on the frontend on your backend with [Get Server](https://github.com/jonataslaw/get_server)**.
  70 +
  71 +**In addition, the entire development process can be completely automated, both on the server and on the front end with [Get CLI](https://github.com/jonataslaw/get_cli)**.
  72 +
  73 +**In addition, to further increase your productivity, we have the
  74 +[extension to VSCode](https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets) and the [extension to Android Studio/Intellij](https://plugins.jetbrains.com/plugin/14975-getx-snippets)**
  75 +
  76 +# Installing
  77 +
  78 +Add Get to your pubspec.yaml file:
  79 +
  80 +```yaml
  81 +dependencies:
  82 + get:
  83 +```
  84 +
  85 +Import get in files that it will be used:
  86 +
  87 +```dart
  88 +import 'package:get/get.dart';
  89 +```
  90 +
  91 +# Counter App with GetX
  92 +
  93 +The "counter" project created by default on new project on Flutter has over 100 lines (with comments). To show the power of Get, I will demonstrate how to make a "counter" changing the state with each click, switching between pages and sharing the state between screens, all in an organized way, separating the business logic from the view, in ONLY 26 LINES CODE INCLUDING COMMENTS.
  94 +
  95 +- Step 1:
  96 + Add "Get" before your MaterialApp, turning it into GetMaterialApp
  97 +
  98 +```dart
  99 +void main() => runApp(GetMaterialApp(home: Home()));
  100 +```
  101 +
  102 +- Note: this does not modify the MaterialApp of the Flutter, GetMaterialApp is not a modified MaterialApp, it is just a pre-configured Widget, which has the default MaterialApp as a child. You can configure this manually, but it is definitely not necessary. GetMaterialApp will create routes, inject them, inject translations, inject everything you need for route navigation. If you use Get only for state management or dependency management, it is not necessary to use GetMaterialApp. GetMaterialApp is necessary for routes, snackbars, internationalization, bottomSheets, dialogs, and high-level apis related to routes and absence of context.
  103 +- Note²: This step in only necessary if you gonna use route management (`Get.to()`, `Get.back()` and so on). If you not gonna use it then it is not necessary to do step 1
  104 +
  105 +- Step 2:
  106 + Create your business logic class and place all variables, methods and controllers inside it.
  107 + You can make any variable observable using a simple ".obs".
  108 +
  109 +```dart
  110 +class Controller extends GetxController{
  111 + var count = 0.obs;
  112 + increment() => count++;
  113 +}
  114 +```
  115 +
  116 +- Step 3:
  117 + Create your View, use StatelessWidget and save some RAM, with Get you may no longer need to use StatefulWidget.
  118 +
  119 +```dart
  120 +class Home extends StatelessWidget {
  121 +
  122 + // Instantiate your class using Get.put() to make it available for all "child" routes there.
  123 + final Controller c = Get.put(Controller());
  124 +
  125 + @override
  126 + Widget build(context) => Scaffold(
  127 + // Use Obx(()=> to update Text() whenever count is changed.
  128 + appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))),
  129 +
  130 + // Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context
  131 + body: Center(child: RaisedButton(
  132 + child: Text("Go to Other"), onPressed: () => Get.to(Other()))),
  133 + floatingActionButton:
  134 + FloatingActionButton(child: Icon(Icons.add), onPressed: c.increment));
  135 +}
  136 +
  137 +class Other extends StatelessWidget {
  138 + // You can ask Get to find a Controller that is being used by another page and redirect you to it.
  139 + final Controller c = Get.find();
  140 +
  141 + @override
  142 + Widget build(context){
  143 + // Access the updated count variable
  144 + return Scaffold(body: Center(child: Text("${c.count}")));
  145 + }
  146 +}
  147 +```
  148 +
  149 +Result:
  150 +
  151 +![](counter-app-gif.gif)
  152 +
  153 +This is a simple project but it already makes clear how powerful Get is. As your project grows, this difference will become more significant.
  154 +
  155 +Get was designed to work with teams, but it makes the job of an individual developer simple.
  156 +
  157 +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!
  158 +
  159 +# The Three pillars
  160 +
  161 +## State management
  162 +
  163 +There are currently several state managers for Flutter. However, most of them involve using ChangeNotifier to update widgets and this is a bad and very bad approach to performance of medium or large applications. You can check in the official Flutter documentation that [ChangeNotifier should be used with 1 or a maximum of 2 listeners](https://api.flutter.dev/flutter/foundation/ChangeNotifier-class.html), making it practically unusable for any application medium or large.
  164 +
  165 +Get isn't better or worse than any other state manager, but that you should analyze these points as well as the points below to choose between using Get in pure form (Vanilla), or using it in conjunction with another state manager.
  166 +
  167 +Definitely, Get is not the enemy of any other state manager, because Get is a microframework, not just a state manager, and can be used either alone or in conjunction with them.
  168 +
  169 +Get has two different state managers: the simple state manager (we'll call it GetBuilder) and the reactive state manager (who has the package name, GetX)
  170 +
  171 +### Reactive State Manager
  172 +
  173 +Reactive programming can alienate many people because it is said to be complicated. GetX turns reactive programming into something quite simple:
  174 +
  175 +- You won't need to create StreamControllers.
  176 +- You won't need to create a StreamBuilder for each variable
  177 +- You will not need to create a class for each state.
  178 +- You will not need to create a get for an initial value.
  179 +
  180 +Reactive programming with Get is as easy as using setState.
  181 +
  182 +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.
  183 +
  184 +This is your count variable:
  185 +
  186 +```dart
  187 +var name = 'Jonatas Borges';
  188 +```
  189 +
  190 +To make it observable, you just need to add ".obs" to the end of it:
  191 +
  192 +```dart
  193 +var name = 'Jonatas Borges'.obs;
  194 +```
  195 +
  196 +And in the UI, when you want to show that value and update the screen whenever tha values changes, simply do this:
  197 +
  198 +```dart
  199 +Obx(() => Text("${controller.name}"));
  200 +```
  201 +
  202 +That's all. It's _that_ simple.
  203 +
  204 +### More details about state management
  205 +
  206 +**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 stage manager and the reactive state manager**
  207 +
  208 +You will get a good idea of GetX power.
  209 +
  210 +## Route management
  211 +
  212 +If you are going to use routes/snackbars/dialogs/bottomsheets without context, GetX is excellent for you too, just see it:
  213 +
  214 +Add "Get" before your MaterialApp, turning it into GetMaterialApp
  215 +
  216 +```dart
  217 +GetMaterialApp( // Before: MaterialApp(
  218 + home: MyHome(),
  219 +)
  220 +```
  221 +
  222 +Navigate to new screen:
  223 +
  224 +```dart
  225 +
  226 +Get.to(NextScreen());
  227 +```
  228 +
  229 +Navigate to new screen with name. See more details on named routes [here](./documentation/en_US/route_management.md#navigation-with-named-routes)
  230 +
  231 +```dart
  232 +
  233 +Get.toNamed('/details');
  234 +```
  235 +
  236 +To close snackbars, dialogs, bottomsheets, or anything you would normally close with Navigator.pop(context);
  237 +
  238 +```dart
  239 +Get.back();
  240 +```
  241 +
  242 +To go to the next screen and no option to go back to the previous screen (for use in SplashScreens, login screens and etc.)
  243 +
  244 +```dart
  245 +Get.off(NextScreen());
  246 +```
  247 +
  248 +To go to the next screen and cancel all previous routes (useful in shopping carts, polls, and tests)
  249 +
  250 +```dart
  251 +Get.offAll(NextScreen());
  252 +```
  253 +
  254 +Noticed that you didn't had 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.
  255 +
  256 +### More details about route management
  257 +
  258 +**Get work with named routes and also offer a lower level control over your routes! There is a in-depth documentation [here](./documentation/en_US/route_management.md)**
  259 +
  260 +## Dependency management
  261 +
  262 +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:
  263 +
  264 +```dart
  265 +Controller controller = Get.put(Controller()); // Rather Controller controller = Controller();
  266 +```
  267 +
  268 +- Note: If you are using Get's State Manager, pay more attention to the bindings api, which will make easier to connect your view to your controller.
  269 +
  270 +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.
  271 +So you can use your controller (or class Bloc) normally
  272 +
  273 +**Tip:** 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 rewrite it all, you can use this dependency injection with no problems at all
  274 +
  275 +```dart
  276 +controller.fetchApi();
  277 +```
  278 +
  279 +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:
  280 +
  281 +```dart
  282 +Controller controller = Get.find();
  283 +//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.
  284 +```
  285 +
  286 +And then you will be able to recover your controller data that was obtained back there:
  287 +
  288 +```dart
  289 +Text(controller.textFromApi);
  290 +```
  291 +
  292 +### More details about dependency management
  293 +
  294 +**See a more in-depth explanation of dependency management [here](./documentation/en_US/dependency_management.md)**
  295 +
  296 +# Utils
  297 +
  298 +## Internationalization
  299 +
  300 +### Translations
  301 +
  302 +Translations are kept as a simple key-value dictionary map.
  303 +To add custom translations, create a class and extend `Translations`.
  304 +
  305 +```dart
  306 +import 'package:get/get.dart';
  307 +
  308 +class Messages extends Translations {
  309 + @override
  310 + Map<String, Map<String, String>> get keys => {
  311 + 'en_US': {
  312 + 'hello': 'Hello World',
  313 + },
  314 + 'de_DE': {
  315 + 'hello': 'Hallo Welt',
  316 + }
  317 + };
  318 +}
  319 +```
  320 +
  321 +#### Using translations
  322 +
  323 +Just append `.tr` to the specified key and it will be translated, using the current value of `Get.locale` and `Get.fallbackLocale`.
  324 +
  325 +```dart
  326 +Text('title'.tr);
  327 +```
  328 +
  329 +### Locales
  330 +
  331 +Pass parameters to `GetMaterialApp` to define the locale and translations.
  332 +
  333 +```dart
  334 +return GetMaterialApp(
  335 + translations: Messages(), // your translations
  336 + locale: Locale('en', 'US'), // translations will be displayed in that locale
  337 + fallbackLocale: Locale('en', 'UK'), // specify the fallback locale in case an invalid locale is selected.
  338 +);
  339 +```
  340 +
  341 +#### Change locale
  342 +
  343 +Call `Get.updateLocale(locale)` to update the locale. Translations then automatically use the new locale.
  344 +
  345 +```dart
  346 +var locale = Locale('en', 'US');
  347 +Get.updateLocale(locale);
  348 +```
  349 +
  350 +#### System locale
  351 +
  352 +To read the system locale, you could use `window.locale`.
  353 +
  354 +```dart
  355 +import 'dart:ui' as ui;
  356 +
  357 +return GetMaterialApp(
  358 + locale: ui.window.locale,
  359 +);
  360 +```
  361 +
  362 +## Change Theme
  363 +
  364 +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™**.
  365 +
  366 +You can create your custom theme and simply add it within `Get.changeTheme` without any boilerplate for that:
  367 +
  368 +```dart
  369 +Get.changeTheme(ThemeData.light());
  370 +```
  371 +
  372 +If you want to create something like a button that changes the Theme in `onTap`, you can combine two **GetX™** APIs for that:
  373 +
  374 +- The api that checks if the dark `Theme` is being used.
  375 +- And the `Theme` Change API, you can just put this within an `onPressed`:
  376 +
  377 +```dart
  378 +Get.changeTheme(Get.isDarkMode? ThemeData.light(): ThemeData.dark());
  379 +```
  380 +
  381 +When `.darkmode` is activated, it will switch to the _light theme_, and when the _light theme_ becomes active, it will change to _dark theme_.
  382 +
  383 +## Other Advanced APIs
  384 +
  385 +```dart
  386 +// give the current args from currentScreen
  387 +Get.arguments
  388 +
  389 +// give arguments of previous route
  390 +Get.previousArguments
  391 +
  392 +// give name of previous route
  393 +Get.previousRoute
  394 +
  395 +// give the raw route to access for example, rawRoute.isFirst()
  396 +Get.rawRoute
  397 +
  398 +// give access to Rounting API from GetObserver
  399 +Get.routing
  400 +
  401 +// check if snackbar is open
  402 +Get.isSnackbarOpen
  403 +
  404 +// check if dialog is open
  405 +Get.isDialogOpen
  406 +
  407 +// check if bottomsheet is open
  408 +Get.isBottomSheetOpen
  409 +
  410 +// remove one route.
  411 +Get.removeRoute()
  412 +
  413 +// back repeatedly until the predicate returns true.
  414 +Get.until()
  415 +
  416 +// go to next route and remove all the previous routes until the predicate returns true.
  417 +Get.offUntil()
  418 +
  419 +// go to next named route and remove all the previous routes until the predicate returns true.
  420 +Get.offNamedUntil()
  421 +
  422 +//Check in what platform the app is running
  423 +GetPlatform.isAndroid
  424 +GetPlatform.isIOS
  425 +GetPlatform.isMacOS
  426 +GetPlatform.isWindows
  427 +GetPlatform.isLinux
  428 +GetPlatform.isFuchsia
  429 +
  430 +//Check the device type
  431 +GetPlatform.isMobile
  432 +GetPlatform.isDesktop
  433 +//All platforms are supported independently in web!
  434 +//You can tell if you are running inside a browser
  435 +//on Windows, iOS, OSX, Android, etc.
  436 +GetPlatform.isWeb
  437 +
  438 +
  439 +// Equivalent to : MediaQuery.of(context).size.height,
  440 +// but immutable.
  441 +Get.height
  442 +Get.width
  443 +
  444 +// Gives the current context of the Navigator.
  445 +Get.context
  446 +
  447 +// Gives the context of the snackbar/dialog/bottomsheet in the foreground, anywhere in your code.
  448 +Get.contextOverlay
  449 +
  450 +// Note: the following methods are extensions on context. Since you
  451 +// have access to context in any place of your UI, you can use it anywhere in the UI code
  452 +
  453 +// If you need a changeable height/width (like Desktop or browser windows that can be scaled) you will need to use context.
  454 +context.width
  455 +context.height
  456 +
  457 +// Gives you the power to define half the screen, a third of it and so on.
  458 +// Useful for responsive applications.
  459 +// param dividedBy (double) optional - default: 1
  460 +// param reducedBy (double) optional - default: 0
  461 +context.heightTransformer()
  462 +context.widthTransformer()
  463 +
  464 +/// Similar to MediaQuery.of(context).size
  465 +context.mediaQuerySize()
  466 +
  467 +/// Similar to MediaQuery.of(context).padding
  468 +context.mediaQueryPadding()
  469 +
  470 +/// Similar to MediaQuery.of(context).viewPadding
  471 +context.mediaQueryViewPadding()
  472 +
  473 +/// Similar to MediaQuery.of(context).viewInsets;
  474 +context.mediaQueryViewInsets()
  475 +
  476 +/// Similar to MediaQuery.of(context).orientation;
  477 +context.orientation()
  478 +
  479 +/// Check if device is on landscape mode
  480 +context.isLandscape()
  481 +
  482 +/// Check if device is on portrait mode
  483 +context.isPortrait()
  484 +
  485 +/// Similar to MediaQuery.of(context).devicePixelRatio;
  486 +context.devicePixelRatio()
  487 +
  488 +/// Similar to MediaQuery.of(context).textScaleFactor;
  489 +context.textScaleFactor()
  490 +
  491 +/// Get the shortestSide from screen
  492 +context.mediaQueryShortestSide()
  493 +
  494 +/// True if width be larger than 800
  495 +context.showNavbar()
  496 +
  497 +/// True if the shortestSide is smaller than 600p
  498 +context.isPhone()
  499 +
  500 +/// True if the shortestSide is largest than 600p
  501 +context.isSmallTablet()
  502 +
  503 +/// True if the shortestSide is largest than 720p
  504 +context.isLargeTablet()
  505 +
  506 +/// True if the current device is Tablet
  507 +context.isTablet()
  508 +
  509 +/// Returns a value<T> according to the screen size
  510 +/// can give value for:
  511 +/// watch: if the shortestSide is smaller than 300
  512 +/// mobile: if the shortestSide is smaller than 600
  513 +/// tablet: if the shortestSide is smaller than 1200
  514 +/// desktop: if width is largest than 1200
  515 +context.responsiveValue<T>()
  516 +```
  517 +
  518 +### Optional Global Settings and Manual configurations
  519 +
  520 +GetMaterialApp configures everything for you, but if you want to configure Get manually.
  521 +
  522 +```dart
  523 +MaterialApp(
  524 + navigatorKey: Get.key,
  525 + navigatorObservers: [GetObserver()],
  526 +);
  527 +```
  528 +
  529 +You will also be able to use your own Middleware within `GetObserver`, this will not influence anything.
  530 +
  531 +```dart
  532 +MaterialApp(
  533 + navigatorKey: Get.key,
  534 + navigatorObservers: [
  535 + GetObserver(MiddleWare.observer) // Here
  536 + ],
  537 +);
  538 +```
  539 +
  540 +You can create _Global Settings_ for `Get`. Just add `Get.config` to your code before pushing any route.
  541 +Or do it directly in your `GetMaterialApp`
  542 +
  543 +```dart
  544 +GetMaterialApp(
  545 + enableLog: true,
  546 + defaultTransition: Transition.fade,
  547 + opaqueRoute: Get.isOpaqueRouteDefault,
  548 + popGesture: Get.isPopGestureEnable,
  549 + transitionDuration: Get.defaultDurationTransition,
  550 + defaultGlobalState: Get.defaultGlobalState,
  551 +);
  552 +
  553 +Get.config(
  554 + enableLog = true,
  555 + defaultPopGesture = true,
  556 + defaultTransition = Transitions.cupertino
  557 +)
  558 +```
  559 +
  560 +You can optionally redirect all the logging messages from `Get`.
  561 +If you want to use your own, favourite logging package,
  562 +and want to capture the logs there:
  563 +
  564 +```dart
  565 +GetMaterialApp(
  566 + enableLog: true,
  567 + logWriterCallback: localLogWriter,
  568 +);
  569 +
  570 +void localLogWriter(String text, {bool isError = false}) {
  571 + // pass the message to your favourite logging package here
  572 + // please note that even if enableLog: false log messages will be pushed in this callback
  573 + // you get check the flag if you want through GetConfig.isLogEnable
  574 +}
  575 +
  576 +```
  577 +
  578 +### Local State Widgets
  579 +
  580 +These Widgets allows you to manage a single value, and keep the state ephemeral and locally.
  581 +We have flavours for Reactive and Simple.
  582 +For instance, you might use them to toggle obscureText in a `TextField`, maybe create a custom
  583 +Expandable Panel, or maybe modify the current index in `BottomNavigationBar` while changing the content
  584 +of the body in a `Scaffold`.
  585 +
  586 +#### ValueBuilder
  587 +
  588 +A simplification of `StatefulWidget` that works with a `.setState` callback that takes the updated value.
  589 +
  590 +```dart
  591 +ValueBuilder<bool>(
  592 + initialValue: false,
  593 + builder: (value, updateFn) => Switch(
  594 + value: value,
  595 + onChanged: updateFn, // same signature! you could use ( newValue ) => updateFn( newValue )
  596 + ),
  597 + // if you need to call something outside the builder method.
  598 + onUpdate: (value) => print("Value updated: $value"),
  599 + onDispose: () => print("Widget unmounted"),
  600 +),
  601 +```
  602 +
  603 +#### ObxValue
  604 +
  605 +Similar to [`ValueBuilder`](#valuebuilder), but this is the Reactive version, you pass a Rx instance (remember the magical .obs?) and
  606 +updates automatically... isn't it awesome?
  607 +
  608 +```dart
  609 +ObxValue((data) => Switch(
  610 + value: data.value,
  611 + onChanged: data, // Rx has a _callable_ function! You could use (flag) => data.value = flag,
  612 + ),
  613 + false.obs,
  614 +),
  615 +```
  616 +
  617 +## Useful tips
  618 +
  619 +`.obs`ervables (also known as _Rx_ Types) have a wide variety of internal methods and operators.
  620 +
  621 +> Is very common to _believe_ that a property with `.obs` **IS** the actual value... but make no mistake!
  622 +> We avoid the Type declaration of the variable, because Dart's compiler is smart enough, and the code
  623 +> looks cleaner, but:
  624 +
  625 +```dart
  626 +var message = 'Hello world'.obs;
  627 +print( 'Message "$message" has Type ${message.runtimeType}');
  628 +```
  629 +
  630 +Even if `message` _prints_ the actual String value, the Type is **RxString**!
  631 +
  632 +So, you can't do `message.substring( 0, 4 )`.
  633 +You have to access the real `value` inside the _observable_:
  634 +The most "used way" is `.value`, but, did you know that you can also use...
  635 +
  636 +```dart
  637 +final name = 'GetX'.obs;
  638 +// only "updates" the stream, if the value is different from the current one.
  639 +name.value = 'Hey';
  640 +
  641 +// All Rx properties are "callable" and returns the new value.
  642 +// but this approach does not accepts `null`, the UI will not rebuild.
  643 +name('Hello');
  644 +
  645 +// is like a getter, prints 'Hello'.
  646 +name() ;
  647 +
  648 +/// numbers:
  649 +
  650 +final count = 0.obs;
  651 +
  652 +// You can use all non mutable operations from num primitives!
  653 +count + 1;
  654 +
  655 +// Watch out! this is only valid if `count` is not final, but var
  656 +count += 1;
  657 +
  658 +// You can also compare against values:
  659 +count > 2;
  660 +
  661 +/// booleans:
  662 +
  663 +final flag = false.obs;
  664 +
  665 +// switches the value between true/false
  666 +flag.toggle();
  667 +
  668 +
  669 +/// all types:
  670 +
  671 +// Sets the `value` to null.
  672 +flag.nil();
  673 +
  674 +// All toString(), toJson() operations are passed down to the `value`
  675 +print( count ); // calls `toString()` inside for RxInt
  676 +
  677 +final abc = [0,1,2].obs;
  678 +// Converts the value to a json Array, prints RxList
  679 +// Json is supported by all Rx types!
  680 +print('json: ${jsonEncode(abc)}, type: ${abc.runtimeType}');
  681 +
  682 +// RxMap, RxList and RxSet are special Rx types, that extends their native types.
  683 +// but you can work with a List as a regular list, although is reactive!
  684 +abc.add(12); // pushes 12 to the list, and UPDATES the stream.
  685 +abc[3]; // like Lists, reads the index 3.
  686 +
  687 +
  688 +// equality works with the Rx and the value, but hashCode is always taken from the value
  689 +final number = 12.obs;
  690 +print( number == 12 ); // prints > true
  691 +
  692 +/// Custom Rx Models:
  693 +
  694 +// toJson(), toString() are deferred to the child, so you can implement override on them, and print() the observable directly.
  695 +
  696 +class User {
  697 + String name, last;
  698 + int age;
  699 + User({this.name, this.last, this.age});
  700 +
  701 + @override
  702 + String toString() => '$name $last, $age years old';
  703 +}
  704 +
  705 +final user = User(name: 'John', last: 'Doe', age: 33).obs;
  706 +
  707 +// `user` is "reactive", but the properties inside ARE NOT!
  708 +// So, if we change some variable inside of it...
  709 +user.value.name = 'Roi';
  710 +// The widget will not rebuild!,
  711 +// `Rx` don't have any clue when you change something inside user.
  712 +// So, for custom classes, we need to manually "notify" the change.
  713 +user.refresh();
  714 +
  715 +// or we can use the `update()` method!
  716 +user.update((value){
  717 + value.name='Roi';
  718 +});
  719 +
  720 +print( user );
  721 +```
  722 +
  723 +#### GetView
  724 +
  725 +I love this Widget, is so simple, yet, so useful!
  726 +
  727 +Is a `const Stateless` Widget that has a getter `controller` for a registered `Controller`, that's all.
  728 +
  729 +```dart
  730 + class AwesomeController extends GetxController {
  731 + final String title = 'My Awesome View';
  732 + }
  733 +
  734 + // ALWAYS remember to pass the `Type` you used to register your controller!
  735 + class AwesomeView extends GetView<AwesomeController> {
  736 + @override
  737 + Widget build(BuildContext context) {
  738 + return Container(
  739 + padding: EdgeInsets.all(20),
  740 + child: Text( controller.title ), // just call `controller.something`
  741 + );
  742 + }
  743 + }
  744 +```
  745 +
  746 +#### GetWidget
  747 +
  748 +Most people have no idea about this Widget, or totally confuse the usage of it.
  749 +The use case is very rare, but very specific: It `caches` a Controller.
  750 +Because of the _cache_, can't be a `const Stateless`.
  751 +
  752 +> So, when do you need to "cache" a Controller?
  753 +
  754 +If you use, another "not so common" feature of **GetX**: `Get.create()`.
  755 +
  756 +`Get.create(()=>Controller())` will generate a new `Controller` each time you call
  757 +`Get.find<Controller>()`,
  758 +
  759 +That's where `GetWidget` shines... as you can use it, for example,
  760 +to keep a list of Todo items. So, if the widget gets "rebuilt", it will keep the same controller instance.
  761 +
  762 +#### GetxService
  763 +
  764 +This class is like a `GetxController`, it shares the same lifecycle ( `onInit()`, `onReady()`, `onClose()`).
  765 +But has no "logic" inside of it. It just notifies **GetX** Dependency Injection system, that this subclass
  766 +**can not** be removed from memory.
  767 +
  768 +So is super useful to keep your "Services" always reachable and active with `Get.find()`. Like:
  769 +`ApiService`, `StorageService`, `CacheService`.
  770 +
  771 +```dart
  772 +Future<void> main() async {
  773 + await initServices(); /// AWAIT SERVICES INITIALIZATION.
  774 + runApp(SomeApp());
  775 +}
  776 +
  777 +/// Is a smart move to make your Services intiialize before you run the Flutter app.
  778 +/// as you can control the execution flow (maybe you need to load some Theme configuration,
  779 +/// apiKey, language defined by the User... so load SettingService before running ApiService.
  780 +/// so GetMaterialApp() doesnt have to rebuild, and takes the values directly.
  781 +void initServices() async {
  782 + print('starting services ...');
  783 + /// Here is where you put get_storage, hive, shared_pref initialization.
  784 + /// or moor connection, or whatever that's async.
  785 + await Get.putAsync(() => DbService().init());
  786 + await Get.putAsync(SettingsService()).init();
  787 + print('All services started...');
  788 +}
  789 +
  790 +class DbService extends GetxService {
  791 + Future<DbService> init() async {
  792 + print('$runtimeType delays 2 sec');
  793 + await 2.delay();
  794 + print('$runtimeType ready!');
  795 + return this;
  796 + }
  797 +}
  798 +
  799 +class SettingsService extends GetxService {
  800 + void init() async {
  801 + print('$runtimeType delays 1 sec');
  802 + await 1.delay();
  803 + print('$runtimeType ready!');
  804 + }
  805 +}
  806 +
  807 +```
  808 +
  809 +The only way to actually delete a `GetxService`, is with `Get.reset()` which is like a
  810 +"Hot Reboot" of your app. So remember, if you need absolute persistance of a class instance during the
  811 +lifetime of your app, use `GetxService`.
  812 +
  813 +# Breaking changes from 2.0
  814 +
  815 +1- Rx types:
  816 +
  817 +| Before | After |
  818 +| ------- | ---------- |
  819 +| StringX | `RxString` |
  820 +| IntX | `RxInt` |
  821 +| MapX | `RxMap` |
  822 +| ListX | `RxList` |
  823 +| NumX | `RxNum` |
  824 +| DoubleX | `RxDouble` |
  825 +
  826 +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.
  827 +
  828 +2- NamedRoutes
  829 +Before:
  830 +
  831 +```dart
  832 +GetMaterialApp(
  833 + namedRoutes: {
  834 + '/': GetRoute(page: Home()),
  835 + }
  836 +)
  837 +```
  838 +
  839 +Now:
  840 +
  841 +```dart
  842 +GetMaterialApp(
  843 + getPages: [
  844 + GetPage(name: '/', page: () => Home()),
  845 + ]
  846 +)
  847 +```
  848 +
  849 +Why this change?
  850 +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.
  851 +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:
  852 +
  853 +```dart
  854 +
  855 +GetStorage box = GetStorage();
  856 +
  857 +GetMaterialApp(
  858 + getPages: [
  859 + GetPage(name: '/', page:(){
  860 + return box.hasData('token') ? Home() : Login();
  861 + })
  862 + ]
  863 +)
  864 +```
  865 +
  866 +# Why Getx?
  867 +
  868 +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.
  869 +
  870 +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.
  871 +
  872 +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.
  873 +
  874 +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.
  875 +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.
  876 +
  877 +This library will always be updated and implementing new features. Feel free to offer PRs and contribute to them.
  878 +
  879 +# Community
  880 +
  881 +## Community channels
  882 +
  883 +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.
  884 +
  885 +| **Slack** | **Discord** | **Telegram** |
  886 +| :-------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
  887 +| [![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) |
  888 +
  889 +## How to contribute
  890 +
  891 +_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._
  892 +
  893 +- Helping to translate the readme into other languages.
  894 +- Adding documentation to the readme (a lot of Get's functions haven't been documented yet).
  895 +- Write articles or make videos teaching how to use Get (they will be inserted in the Readme and in the future in our Wiki).
  896 +- Offering PRs for code/tests.
  897 +- Including new functions.
  898 +
  899 +Any contribution is welcome!
  900 +
  901 +## Articles and videos
  902 +
  903 +- [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).
  904 +- [Complete GetX™ Navigation](https://www.youtube.com/watch?v=RaqPIoJSTtI) - Route management video by Amateur Coder.
  905 +- [Complete GetX State Management](https://www.youtube.com/watch?v=CNpXbeI_slw) - State management video by Amateur Coder.
  906 +- [GetX™ Other Features](https://youtu.be/ttQtlX_Q0eU) - Utils, storage, bindings and other features video by Amateur Coder.
  907 +- [Firestore User with GetX | Todo App](https://www.youtube.com/watch?v=BiV0DcXgk58) - Video by Amateur Coder.
  908 +- [Firebase Auth with GetX | Todo App](https://www.youtube.com/watch?v=-H-T_BSgfOE) - Video by Amateur Coder.
  909 +- [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).
  910 +- [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.
  911 +- [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.
  912 +- [GetX Flutter Firebase Auth Example](https://medium.com/@jeffmcmorris/getx-flutter-firebase-auth-example-b383c1dd1de2) - Article by Jeff McMorris.