Nicolas Lopez

StateMixin doc and some fixes

@@ -916,6 +916,55 @@ user.update((value){ @@ -916,6 +916,55 @@ user.update((value){
916 916
917 print( user ); 917 print( user );
918 ``` 918 ```
  919 +## StateMixin
  920 +
  921 +Another way to handle your `UI` state is use the `StateMixin<T>` .
  922 +To implement it, use the `with` to add the `StateMixin<T>`
  923 +to your controller which allows a T model.
  924 +
  925 +``` dart
  926 +class Controller extends GetController with StateMixin<User>{}
  927 +```
  928 +
  929 +The `change()` method change the State whenever we want.
  930 +Just pass the data and the status in this way:
  931 +
  932 +```dart
  933 +change(data, status: RxStatus.success());
  934 +```
  935 +
  936 +RxStatus allow these status:
  937 +
  938 +``` dart
  939 +RxStatus.loading();
  940 +RxStatus.success();
  941 +RxStatus.empty();
  942 +RxStatus.error('message');
  943 +```
  944 +
  945 +To represent it in the UI, use:
  946 +
  947 +```dart
  948 +class OtherClass extends GetView<Controller> {
  949 + @override
  950 + Widget build(BuildContext context) {
  951 + return Scaffold(
  952 +
  953 + body: controller.obx(
  954 + (state)=>Text(state.name),
  955 +
  956 + // here you can put your custom loading indicator, but
  957 + // by default would be Center(child:CircularProgressIndicator())
  958 + onLoading: CustomLoadingIndicator(),
  959 + onEmpty: Text('No data found'),
  960 +
  961 + // here also you can set your own error widget, but by
  962 + // default will be an Center(child:Text(error))
  963 + onError: (error)=>Text(error),
  964 + ),
  965 + );
  966 +}
  967 +```
919 968
920 #### GetView 969 #### GetView
921 970
@@ -924,7 +973,7 @@ I love this Widget, is so simple, yet, so useful! @@ -924,7 +973,7 @@ I love this Widget, is so simple, yet, so useful!
924 Is a `const Stateless` Widget that has a getter `controller` for a registered `Controller`, that's all. 973 Is a `const Stateless` Widget that has a getter `controller` for a registered `Controller`, that's all.
925 974
926 ```dart 975 ```dart
927 - class AwesomeController extends GetxController { 976 + class AwesomeController extends GetController {
928 final String title = 'My Awesome View'; 977 final String title = 'My Awesome View';
929 } 978 }
930 979
1 -- [State Management](#state-management)  
2 - - [Reactive State Manager](#reactive-state-manager) 1 +* [State Management](#state-management)
  2 + + [Reactive State Manager](#reactive-state-manager)
3 - [Advantages](#advantages) 3 - [Advantages](#advantages)
4 - [Maximum performance:](#maximum-performance) 4 - [Maximum performance:](#maximum-performance)
5 - [Declaring a reactive variable](#declaring-a-reactive-variable) 5 - [Declaring a reactive variable](#declaring-a-reactive-variable)
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 - [Why i have to use .value](#why-i-have-to-use-value) 11 - [Why i have to use .value](#why-i-have-to-use-value)
12 - [Obx()](#obx) 12 - [Obx()](#obx)
13 - [Workers](#workers) 13 - [Workers](#workers)
14 - - [Simple State Manager](#simple-state-manager) 14 + + [Simple State Manager](#simple-state-manager)
15 - [Advantages](#advantages-1) 15 - [Advantages](#advantages-1)
16 - [Usage](#usage) 16 - [Usage](#usage)
17 - [How it handles controllers](#how-it-handles-controllers) 17 - [How it handles controllers](#how-it-handles-controllers)
@@ -19,30 +19,35 @@ @@ -19,30 +19,35 @@
19 - [Why it exists](#why-it-exists) 19 - [Why it exists](#why-it-exists)
20 - [Other ways of using it](#other-ways-of-using-it) 20 - [Other ways of using it](#other-ways-of-using-it)
21 - [Unique IDs](#unique-ids) 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) 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 24
25 # State Management 25 # State Management
26 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. 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 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. 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 +
31 With GetX everything is reactive, and nothing depends on code generators, increasing your productivity in all aspects of your development. 32 With GetX everything is reactive, and nothing depends on code generators, increasing your productivity in all aspects of your development.
32 -- _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.  
33 -- _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. 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 +
34 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. 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.
35 -- _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. 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 +
36 Most (if not all) current state managers will rebuild on the screen. 41 Most (if not all) current state managers will rebuild on the screen.
37 42
38 ## Reactive State Manager 43 ## Reactive State Manager
39 44
40 Reactive programming can alienate many people because it is said to be complicated. GetX turns reactive programming into something quite simple: 45 Reactive programming can alienate many people because it is said to be complicated. GetX turns reactive programming into something quite simple:
41 46
42 -- You won't need to create StreamControllers.  
43 -- You won't need to create a StreamBuilder for each variable  
44 -- You will not need to create a class for each state.  
45 -- You will not need to create a get for an initial value. 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.
46 51
47 Reactive programming with Get is as easy as using setState. 52 Reactive programming with Get is as easy as using setState.
48 53
@@ -50,13 +55,13 @@ Let's imagine that you have a name variable and want that every time you change @@ -50,13 +55,13 @@ Let's imagine that you have a name variable and want that every time you change
50 55
51 This is your count variable: 56 This is your count variable:
52 57
53 -```dart 58 +``` dart
54 var name = 'Jonatas Borges'; 59 var name = 'Jonatas Borges';
55 ``` 60 ```
56 61
57 To make it observable, you just need to add ".obs" to the end of it: 62 To make it observable, you just need to add ".obs" to the end of it:
58 63
59 -```dart 64 +``` dart
60 var name = 'Jonatas Borges'.obs; 65 var name = 'Jonatas Borges'.obs;
61 ``` 66 ```
62 67
@@ -64,34 +69,34 @@ That's all. It's *that* simple. @@ -64,34 +69,34 @@ That's all. It's *that* simple.
64 69
65 From now on, we might refer to this reactive-".obs"(ervables) variables as _Rx_. 70 From now on, we might refer to this reactive-".obs"(ervables) variables as _Rx_.
66 71
67 -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. 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.
68 73
69 This is the **magic of GetX**, thanks to Dart's capabilities. 74 This is the **magic of GetX**, thanks to Dart's capabilities.
70 75
71 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". 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".
72 77
73 -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? 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?
74 79
75 -No, you don't need a `StreamBuilder`, but you are right about static classes. 80 +No, you don't need a `StreamBuilder` , but you are right about static classes.
76 81
77 Well, in the view, we usually have a lot of boilerplate when we want to change a specific Widget, that's the Flutter way. 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.
78 With **GetX** you can also forget about this boilerplate code. 83 With **GetX** you can also forget about this boilerplate code.
79 84
80 -`StreamBuilder( … )`? `initialValue: …`? `builder: …`? Nope, you just need to place this variable inside an `Obx()` Widget. 85 +`StreamBuilder( … )` ? `initialValue: …` ? `builder: …` ? Nope, you just need to place this variable inside an `Obx()` Widget.
81 86
82 -```dart 87 +``` dart
83 Obx (() => Text (controller.name)); 88 Obx (() => Text (controller.name));
84 ``` 89 ```
85 90
86 -_What do you need to memorize?_ Only `Obx(() =>`. 91 +_What do you need to memorize?_ Only `Obx(() =>` .
87 92
88 You are just passing that Widget through an arrow-function into an `Obx()` (the "Observer" of the _Rx_). 93 You are just passing that Widget through an arrow-function into an `Obx()` (the "Observer" of the _Rx_).
89 94
90 `Obx` is pretty smart, and will only change if the value of `controller.name` changes. 95 `Obx` is pretty smart, and will only change if the value of `controller.name` changes.
91 96
92 -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?** 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?**
93 98
94 -> So, what if I have 5 _Rx_ (observable) variables within an `Obx`? 99 +> So, what if I have 5 _Rx_ (observable) variables within an `Obx` ?
95 100
96 It will just update when **any** of them changes. 101 It will just update when **any** of them changes.
97 102
@@ -102,28 +107,30 @@ Nope, just the **specific Widget** that uses that _Rx_ variable. @@ -102,28 +107,30 @@ Nope, just the **specific Widget** that uses that _Rx_ variable.
102 So, **GetX** only updates the screen, when the _Rx_ variable changes it's value. 107 So, **GetX** only updates the screen, when the _Rx_ variable changes it's value.
103 108
104 ``` 109 ```
  110 +
105 final isOpen = false.obs; 111 final isOpen = false.obs;
106 112
107 // NOTHING will happen... same value. 113 // NOTHING will happen... same value.
108 void onButtonTap() => isOpen.value=false; 114 void onButtonTap() => isOpen.value=false;
109 ``` 115 ```
  116 +
110 ### Advantages 117 ### Advantages
111 118
112 **GetX()** helps you when you need **granular** control over what's being updated. 119 **GetX()** helps you when you need **granular** control over what's being updated.
113 120
114 -If you do not need `unique IDs`, because all your variables will be modified when you perform an action, then use `GetBuilder`,  
115 -because it's a Simple State Updater (in blocks, like `setState()`), made in just a few lines of code. 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.
116 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. 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.
117 124
118 If you need a **powerful** State Manager, you can't go wrong with **GetX**. 125 If you need a **powerful** State Manager, you can't go wrong with **GetX**.
119 126
120 It doesn't work with variables, but __flows__, everything in it are `Streams` under the hood. 127 It doesn't work with variables, but __flows__, everything in it are `Streams` under the hood.
121 -You can use _rxDart_ in conjunction with it, because everything are `Streams`, 128 +You can use _rxDart_ in conjunction with it, because everything are `Streams` ,
122 you can listen the `event` of each "_Rx_ variable", 129 you can listen the `event` of each "_Rx_ variable",
123 -because everything in it are `Streams`. 130 +because everything in it are `Streams` .
124 131
125 It is literally a _BLoC_ approach, easier than _MobX_, and without code generators or decorations. 132 It is literally a _BLoC_ approach, easier than _MobX_, and without code generators or decorations.
126 -You can turn **anything** into an _"Observable"_ with just a `.obs`. 133 +You can turn **anything** into an _"Observable"_ with just a `.obs` .
127 134
128 ### Maximum performance: 135 ### Maximum performance:
129 136
@@ -134,19 +141,18 @@ If you experience any errors in your app, and send a duplicate change of State, @@ -134,19 +141,18 @@ If you experience any errors in your app, and send a duplicate change of State,
134 **GetX** will ensure it will not crash. 141 **GetX** will ensure it will not crash.
135 142
136 With **GetX** the State only changes if the `value` change. 143 With **GetX** the State only changes if the `value` change.
137 -That's the main difference between **GetX**, and using _`computed` from MobX_. 144 +That's the main difference between **GetX**, and using _ `computed` from MobX_.
138 When joining two __observables__, and one changes; the listener of that _observable_ will change as well. 145 When joining two __observables__, and one changes; the listener of that _observable_ will change as well.
139 146
140 -With **GetX**, if you join two variables, `GetX()` (similar to `Observer()`) will only rebuild if it implies a real change of State. 147 +With **GetX**, if you join two variables, `GetX()` (similar to `Observer()` ) will only rebuild if it implies a real change of State.
141 148
142 ### Declaring a reactive variable 149 ### Declaring a reactive variable
143 150
144 You have 3 ways to turn a variable into an "observable". 151 You have 3 ways to turn a variable into an "observable".
145 152
146 -  
147 1 - The first is using **`Rx{Type}`**. 153 1 - The first is using **`Rx{Type}`**.
148 154
149 -```dart 155 +``` dart
150 // initial value is recommended, but not mandatory 156 // initial value is recommended, but not mandatory
151 final name = RxString(''); 157 final name = RxString('');
152 final isLogged = RxBool(false); 158 final isLogged = RxBool(false);
@@ -158,7 +164,7 @@ final myMap = RxMap<String, int>({}); @@ -158,7 +164,7 @@ final myMap = RxMap<String, int>({});
158 164
159 2 - The second is to use **`Rx`** and use Darts Generics, `Rx<Type>` 165 2 - The second is to use **`Rx`** and use Darts Generics, `Rx<Type>`
160 166
161 -```dart 167 +``` dart
162 final name = Rx<String>(''); 168 final name = Rx<String>('');
163 final isLogged = Rx<Bool>(false); 169 final isLogged = Rx<Bool>(false);
164 final count = Rx<Int>(0); 170 final count = Rx<Int>(0);
@@ -171,9 +177,9 @@ final myMap = Rx<Map<String, int>>({}); @@ -171,9 +177,9 @@ final myMap = Rx<Map<String, int>>({});
171 final user = Rx<User>(); 177 final user = Rx<User>();
172 ``` 178 ```
173 179
174 -3 - The third, more practical, easier and preferred approach, just add **`.obs`** as a property of your `value`: 180 +3 - The third, more practical, easier and preferred approach, just add **`.obs`** as a property of your `value` :
175 181
176 -```dart 182 +``` dart
177 final name = ''.obs; 183 final name = ''.obs;
178 final isLogged = false.obs; 184 final isLogged = false.obs;
179 final count = 0.obs; 185 final count = 0.obs;
@@ -193,20 +199,19 @@ To be prepared, from now on, you should always start your _Rx_ variables with an @@ -193,20 +199,19 @@ To be prepared, from now on, you should always start your _Rx_ variables with an
193 199
194 > Transforming a variable into an _observable_ + _initial value_ with **GetX** is the simplest, and most practical approach. 200 > Transforming a variable into an _observable_ + _initial value_ with **GetX** is the simplest, and most practical approach.
195 201
196 -You will literally add a "`.obs`" to the end of your variable, and **that’s it**, you’ve made it observable,  
197 -and its `.value`, well, will be the _initial value_).  
198 - 202 +You will literally add a " `.obs` " to the end of your variable, and **that’s it**, you’ve made it observable,
  203 +and its `.value` , well, will be the _initial value_).
199 204
200 ### Using the values in the view 205 ### Using the values in the view
201 206
202 -```dart 207 +``` dart
203 // controller file 208 // controller file
204 final count1 = 0.obs; 209 final count1 = 0.obs;
205 final count2 = 0.obs; 210 final count2 = 0.obs;
206 int get sum => count1.value + count2.value; 211 int get sum => count1.value + count2.value;
207 ``` 212 ```
208 213
209 -```dart 214 +``` dart
210 // view file 215 // view file
211 GetX<Controller>( 216 GetX<Controller>(
212 builder: (controller) { 217 builder: (controller) {
@@ -228,30 +233,35 @@ GetX<Controller>( @@ -228,30 +233,35 @@ GetX<Controller>(
228 ), 233 ),
229 ``` 234 ```
230 235
231 -If we increment `count1.value++`, it will print:  
232 -- `count 1 rebuild`  
233 -- `count 3 rebuild` 236 +If we increment `count1.value++` , it will print:
  237 +
  238 +* `count 1 rebuild`
  239 +
  240 +* `count 3 rebuild`
  241 +
  242 +because `count1` has a value of `1` , and `1 + 0 = 1` , changing the `sum` getter value.
234 243
235 -because `count1` has a value of `1`, and `1 + 0 = 1`, changing the `sum` getter value. 244 +If we change `count2.value++` , it will print:
236 245
237 -If we change `count2.value++`, it will print:  
238 -- `count 2 rebuild`  
239 -- `count 3 rebuild` 246 +* `count 2 rebuild`
240 247
241 -because `count2.value` changed, and the result of the `sum` is now `2`. 248 +* `count 3 rebuild`
  249 +
  250 +because `count2.value` changed, and the result of the `sum` is now `2` .
  251 +
  252 +* NOTE: By default, the very first event will rebuild the widget, even if it is the same `value`.
242 253
243 -- NOTE: By default, the very first event will rebuild the widget, even if it is the same `value`.  
244 This behavior exists due to Boolean variables. 254 This behavior exists due to Boolean variables.
245 255
246 Imagine you did this: 256 Imagine you did this:
247 257
248 -```dart 258 +``` dart
249 var isLogged = false.obs; 259 var isLogged = false.obs;
250 ``` 260 ```
251 261
252 -And then, you checked if a user is "logged in" to trigger an event in `ever`. 262 +And then, you checked if a user is "logged in" to trigger an event in `ever` .
253 263
254 -```dart 264 +``` dart
255 @override 265 @override
256 onInit(){ 266 onInit(){
257 ever(isLogged, fireRoute); 267 ever(isLogged, fireRoute);
@@ -267,18 +277,18 @@ fireRoute(logged) { @@ -267,18 +277,18 @@ fireRoute(logged) {
267 } 277 }
268 ``` 278 ```
269 279
270 -if `hasToken` was `false`, there would be no change to `isLogged`, so `ever()` would never be called. 280 +if `hasToken` was `false` , there would be no change to `isLogged` , so `ever()` would never be called.
271 To avoid this type of behavior, the first change to an _observable_ will always trigger an event, 281 To avoid this type of behavior, the first change to an _observable_ will always trigger an event,
272 -even if it contains the same `.value`. 282 +even if it contains the same `.value` .
273 283
274 You can remove this behavior if you want, using: 284 You can remove this behavior if you want, using:
275 -`isLogged.firstRebuild = false;` 285 + `isLogged.firstRebuild = false;`
276 286
277 ### Conditions to rebuild 287 ### Conditions to rebuild
278 288
279 In addition, Get provides refined state control. You can condition an event (such as adding an object to a list), on a certain condition. 289 In addition, Get provides refined state control. You can condition an event (such as adding an object to a list), on a certain condition.
280 290
281 -```dart 291 +``` dart
282 // First parameter: condition, must return true or false. 292 // First parameter: condition, must return true or false.
283 // Second parameter: the new value to apply if the condition is true. 293 // Second parameter: the new value to apply if the condition is true.
284 list.addIf(item < limit, item); 294 list.addIf(item < limit, item);
@@ -288,7 +298,7 @@ Without decorations, without a code generator, without complications :smile: @@ -288,7 +298,7 @@ Without decorations, without a code generator, without complications :smile:
288 298
289 Do you know Flutter's counter app? Your Controller class might look like this: 299 Do you know Flutter's counter app? Your Controller class might look like this:
290 300
291 -```dart 301 +``` dart
292 class CountController extends GetxController { 302 class CountController extends GetxController {
293 final count = 0.obs; 303 final count = 0.obs;
294 } 304 }
@@ -296,7 +306,7 @@ class CountController extends GetxController { @@ -296,7 +306,7 @@ class CountController extends GetxController {
296 306
297 With a simple: 307 With a simple:
298 308
299 -```dart 309 +``` dart
300 controller.count.value++ 310 controller.count.value++
301 ``` 311 ```
302 312
@@ -307,7 +317,8 @@ You could update the counter variable in your UI, regardless of where it is stor @@ -307,7 +317,8 @@ You could update the counter variable in your UI, regardless of where it is stor
307 You can transform anything on obs. Here are two ways of doing it: 317 You can transform anything on obs. Here are two ways of doing it:
308 318
309 * You can convert your class values to obs 319 * You can convert your class values to obs
310 -```dart 320 +
  321 +``` dart
311 class RxUser { 322 class RxUser {
312 final name = "Camila".obs; 323 final name = "Camila".obs;
313 final age = 18.obs; 324 final age = 18.obs;
@@ -315,7 +326,8 @@ class RxUser { @@ -315,7 +326,8 @@ class RxUser {
315 ``` 326 ```
316 327
317 * or you can convert the entire class to be an observable 328 * or you can convert the entire class to be an observable
318 -```dart 329 +
  330 +``` dart
319 class User { 331 class User {
320 User({String name, int age}); 332 User({String name, int age});
321 var name; 333 var name;
@@ -333,7 +345,7 @@ Lists are completely observable as are the objects within it. That way, if you a @@ -333,7 +345,7 @@ Lists are completely observable as are the objects within it. That way, if you a
333 You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that. 345 You also don't need to use ".value" with lists, the amazing dart api allowed us to remove that.
334 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. 346 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.
335 347
336 -```dart 348 +``` dart
337 // On the controller 349 // On the controller
338 final String title = 'User Info:'.obs 350 final String title = 'User Info:'.obs
339 final list = List<User>().obs; 351 final list = List<User>().obs;
@@ -347,7 +359,7 @@ ListView.builder ( @@ -347,7 +359,7 @@ ListView.builder (
347 359
348 When you are making your own classes observable, there is a different way to update them: 360 When you are making your own classes observable, there is a different way to update them:
349 361
350 -```dart 362 +``` dart
351 // on the model file 363 // on the model file
352 // we are going to make the entire class observable instead of each attribute 364 // we are going to make the entire class observable instead of each attribute
353 class User() { 365 class User() {
@@ -356,7 +368,6 @@ class User() { @@ -356,7 +368,6 @@ class User() {
356 int age; 368 int age;
357 } 369 }
358 370
359 -  
360 // on the controller file 371 // on the controller file
361 final user = User().obs; 372 final user = User().obs;
362 // when you need to update the user variable: 373 // when you need to update the user variable:
@@ -385,7 +396,7 @@ You can literally add 3 letters to your pubspec (get) and a colon and start prog @@ -385,7 +396,7 @@ You can literally add 3 letters to your pubspec (get) and a colon and start prog
385 396
386 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. 397 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.
387 398
388 -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. 399 +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.
389 400
390 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. 401 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.
391 402
@@ -400,7 +411,7 @@ Obviously, if you don't use a type, you will need to have an instance of your co @@ -400,7 +411,7 @@ Obviously, if you don't use a type, you will need to have an instance of your co
400 411
401 Workers will assist you, triggering specific callbacks when an event occurs. 412 Workers will assist you, triggering specific callbacks when an event occurs.
402 413
403 -```dart 414 +``` dart
404 /// Called every time `count1` changes. 415 /// Called every time `count1` changes.
405 ever(count1, (_) => print("$_ has been changed")); 416 ever(count1, (_) => print("$_ has been changed"));
406 417
@@ -413,28 +424,34 @@ debounce(count1, (_) => print("debouce$_"), time: Duration(seconds: 1)); @@ -413,28 +424,34 @@ debounce(count1, (_) => print("debouce$_"), time: Duration(seconds: 1));
413 /// Ignore all changes within 1 second. 424 /// Ignore all changes within 1 second.
414 interval(count1, (_) => print("interval $_"), time: Duration(seconds: 1)); 425 interval(count1, (_) => print("interval $_"), time: Duration(seconds: 1));
415 ``` 426 ```
416 -All workers (except `debounce`) have a `condition` named parameter, which can be a `bool` or a callback that returns a `bool`. 427 +
  428 +All workers (except `debounce` ) have a `condition` named parameter, which can be a `bool` or a callback that returns a `bool` .
417 This `condition` defines when the `callback` function executes. 429 This `condition` defines when the `callback` function executes.
418 430
419 All workers returns a `Worker` instance, that you can use to cancel ( via `dispose()` ) the worker. 431 All workers returns a `Worker` instance, that you can use to cancel ( via `dispose()` ) the worker.
420 432
421 -- **`ever`** 433 +
  434 +* **`ever`**
  435 +
422 is called every time the _Rx_ variable emits a new value. 436 is called every time the _Rx_ variable emits a new value.
423 437
424 -- **`everAll`**  
425 - Much like `ever`, but it takes a `List` of _Rx_ values Called every time its variable is changed. That's it. 438 +* **`everAll`**
  439 +
  440 + Much like `ever` , but it takes a `List` of _Rx_ values Called every time its variable is changed. That's it.
426 441
  442 +* **`once`**
427 443
428 -- **`once`**  
429 'once' is called only the first time the variable has been changed. 444 'once' is called only the first time the variable has been changed.
430 445
431 -- **`debounce`** 446 +* **`debounce`**
  447 +
432 '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. 448 '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.
433 449
434 -- **`interval`** 450 +* **`interval`**
  451 +
435 '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. 452 '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.
436 453
437 -- 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). 454 +* 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).
438 455
439 ## Simple State Manager 456 ## Simple State Manager
440 457
@@ -466,7 +483,7 @@ That way, if you want an individual controller, you can assign IDs for that, or @@ -466,7 +483,7 @@ That way, if you want an individual controller, you can assign IDs for that, or
466 483
467 ### Usage 484 ### Usage
468 485
469 -```dart 486 +``` dart
470 // Create controller class and extends GetxController 487 // Create controller class and extends GetxController
471 class Controller extends GetxController { 488 class Controller extends GetxController {
472 int counter = 0; 489 int counter = 0;
@@ -487,13 +504,13 @@ GetBuilder<Controller>( @@ -487,13 +504,13 @@ GetBuilder<Controller>(
487 504
488 **Done!** 505 **Done!**
489 506
490 -- You have already learned how to manage states with Get. 507 +* You have already learned how to manage states with Get.
491 508
492 -- 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. 509 +* 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.
493 510
494 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): 511 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):
495 512
496 -```dart 513 +``` dart
497 class OtherClass extends StatelessWidget { 514 class OtherClass extends StatelessWidget {
498 @override 515 @override
499 Widget build(BuildContext context) { 516 Widget build(BuildContext context) {
@@ -508,9 +525,9 @@ class OtherClass extends StatelessWidget { @@ -508,9 +525,9 @@ class OtherClass extends StatelessWidget {
508 525
509 ``` 526 ```
510 527
511 -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>()`) 528 +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>()` )
512 529
513 -```dart 530 +``` dart
514 class Controller extends GetxController { 531 class Controller extends GetxController {
515 532
516 /// You do not need that. I recommend using it just for ease of syntax. 533 /// You do not need that. I recommend using it just for ease of syntax.
@@ -529,7 +546,7 @@ class Controller extends GetxController { @@ -529,7 +546,7 @@ class Controller extends GetxController {
529 546
530 And then you can access your controller directly, that way: 547 And then you can access your controller directly, that way:
531 548
532 -```dart 549 +``` dart
533 FloatingActionButton( 550 FloatingActionButton(
534 onPressed: () { 551 onPressed: () {
535 Controller.to.increment(), 552 Controller.to.increment(),
@@ -544,7 +561,7 @@ When you press FloatingActionButton, all widgets that are listening to the 'coun @@ -544,7 +561,7 @@ When you press FloatingActionButton, all widgets that are listening to the 'coun
544 561
545 Let's say we have this: 562 Let's say we have this:
546 563
547 -`Class a => Class B (has controller X) => Class C (has controller X)` 564 + `Class a => Class B (has controller X) => Class C (has controller X)`
548 565
549 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. 566 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.
550 567
@@ -557,7 +574,7 @@ Unless you need to use a mixin, like TickerProviderStateMixin, it will be totall @@ -557,7 +574,7 @@ Unless you need to use a mixin, like TickerProviderStateMixin, it will be totall
557 You can call all methods of a StatefulWidget directly from a GetBuilder. 574 You can call all methods of a StatefulWidget directly from a GetBuilder.
558 If you need to call initState() or dispose() method for example, you can call them directly; 575 If you need to call initState() or dispose() method for example, you can call them directly;
559 576
560 -```dart 577 +``` dart
561 GetBuilder<Controller>( 578 GetBuilder<Controller>(
562 initState: (_) => Controller.to.fetchApi(), 579 initState: (_) => Controller.to.fetchApi(),
563 dispose: (_) => Controller.to.closeStreams(), 580 dispose: (_) => Controller.to.closeStreams(),
@@ -567,7 +584,7 @@ GetBuilder<Controller>( @@ -567,7 +584,7 @@ GetBuilder<Controller>(
567 584
568 A much better approach than this is to use the onInit() and onClose() method directly from your controller. 585 A much better approach than this is to use the onInit() and onClose() method directly from your controller.
569 586
570 -```dart 587 +``` dart
571 @override 588 @override
572 void onInit() { 589 void onInit() {
573 fetchApi(); 590 fetchApi();
@@ -575,7 +592,7 @@ void onInit() { @@ -575,7 +592,7 @@ void onInit() {
575 } 592 }
576 ``` 593 ```
577 594
578 -- 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. 595 +* 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.
579 596
580 ### Why it exists 597 ### Why it exists
581 598
@@ -587,7 +604,7 @@ You do not need to call the device, you have the onClose() method that will be c @@ -587,7 +604,7 @@ You do not need to call the device, you have the onClose() method that will be c
587 604
588 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: 605 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:
589 606
590 -```dart 607 +``` dart
591 class Controller extends GetxController { 608 class Controller extends GetxController {
592 StreamController<User> user = StreamController<User>(); 609 StreamController<User> user = StreamController<User>();
593 StreamController<String> name = StreamController<String>(); 610 StreamController<String> name = StreamController<String>();
@@ -604,15 +621,15 @@ class Controller extends GetxController { @@ -604,15 +621,15 @@ class Controller extends GetxController {
604 621
605 Controller life cycle: 622 Controller life cycle:
606 623
607 -- onInit() where it is created.  
608 -- onClose() where it is closed to make any changes in preparation for the delete method  
609 -- 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. 624 +* onInit() where it is created.
  625 +* onClose() where it is closed to make any changes in preparation for the delete method
  626 +* 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.
610 627
611 ### Other ways of using it 628 ### Other ways of using it
612 629
613 You can use Controller instance directly on GetBuilder value: 630 You can use Controller instance directly on GetBuilder value:
614 631
615 -```dart 632 +``` dart
616 GetBuilder<Controller>( 633 GetBuilder<Controller>(
617 init: Controller(), 634 init: Controller(),
618 builder: (value) => Text( 635 builder: (value) => Text(
@@ -623,7 +640,7 @@ GetBuilder<Controller>( @@ -623,7 +640,7 @@ GetBuilder<Controller>(
623 640
624 You may also need an instance of your controller outside of your GetBuilder, and you can use these approaches to achieve this: 641 You may also need an instance of your controller outside of your GetBuilder, and you can use these approaches to achieve this:
625 642
626 -```dart 643 +``` dart
627 class Controller extends GetxController { 644 class Controller extends GetxController {
628 static Controller get to => Get.find(); 645 static Controller get to => Get.find();
629 [...] 646 [...]
@@ -639,7 +656,7 @@ GetBuilder<Controller>( @@ -639,7 +656,7 @@ GetBuilder<Controller>(
639 656
640 or 657 or
641 658
642 -```dart 659 +``` dart
643 class Controller extends GetxController { 660 class Controller extends GetxController {
644 // static Controller get to => Get.find(); // with no static get 661 // static Controller get to => Get.find(); // with no static get
645 [...] 662 [...]
@@ -653,9 +670,9 @@ GetBuilder<Controller>( @@ -653,9 +670,9 @@ GetBuilder<Controller>(
653 ), 670 ),
654 ``` 671 ```
655 672
656 -- 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: 673 +* 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:
657 674
658 -```dart 675 +``` dart
659 Controller controller = Controller(); 676 Controller controller = Controller();
660 [...] 677 [...]
661 GetBuilder<Controller>( 678 GetBuilder<Controller>(
@@ -671,7 +688,7 @@ GetBuilder<Controller>( @@ -671,7 +688,7 @@ GetBuilder<Controller>(
671 688
672 If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs: 689 If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs:
673 690
674 -```dart 691 +``` dart
675 GetBuilder<Controller>( 692 GetBuilder<Controller>(
676 id: 'text' 693 id: 'text'
677 init: Controller(), // use it only first time on each controller 694 init: Controller(), // use it only first time on each controller
@@ -683,13 +700,13 @@ GetBuilder<Controller>( @@ -683,13 +700,13 @@ GetBuilder<Controller>(
683 700
684 And update it this form: 701 And update it this form:
685 702
686 -```dart 703 +``` dart
687 update(['text']); 704 update(['text']);
688 ``` 705 ```
689 706
690 You can also impose conditions for the update: 707 You can also impose conditions for the update:
691 708
692 -```dart 709 +``` dart
693 update(['text'], counter < 10); 710 update(['text'], counter < 10);
694 ``` 711 ```
695 712
@@ -701,6 +718,55 @@ Some people opened a feature request, as they wanted to use only one type of rea @@ -701,6 +718,55 @@ Some people opened a feature request, as they wanted to use only one type of rea
701 718
702 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. 719 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.
703 720
  721 +## StateMixin
  722 +
  723 +Another way to handle your `UI` state is use the `StateMixin<T>` .
  724 +To implement it, use the `with` to add the `StateMixin<T>`
  725 +to your controller which allows a T model.
  726 +
  727 +``` dart
  728 +class Controller extends GetController with StateMixin<User>{}
  729 +```
  730 +
  731 +The `change()` method change the State whenever we want.
  732 +Just pass the data and the status in this way:
  733 +
  734 +```dart
  735 +change(data, status: RxStatus.success());
  736 +```
  737 +
  738 +RxStatus allow these status:
  739 +
  740 +``` dart
  741 +RxStatus.loading();
  742 +RxStatus.success();
  743 +RxStatus.empty();
  744 +RxStatus.error('message');
  745 +```
  746 +
  747 +To represent it in the UI, use:
  748 +
  749 +```dart
  750 +class OtherClass extends GetView<Controller> {
  751 + @override
  752 + Widget build(BuildContext context) {
  753 + return Scaffold(
  754 +
  755 + body: controller.obx(
  756 + (state)=>Text(state.name),
  757 +
  758 + // here you can put your custom loading indicator, but
  759 + // by default would be Center(child:CircularProgressIndicator())
  760 + onLoading: CustomLoadingIndicator(),
  761 + onEmpty: Text('No data found'),
  762 +
  763 + // here also you can set your own error widget, but by
  764 + // default will be an Center(child:Text(error))
  765 + onError: (error)=>Text(error),
  766 + ),
  767 + );
  768 +}
  769 +```
704 770
705 ## GetBuilder vs GetX vs Obx vs MixinBuilder 771 ## GetBuilder vs GetX vs Obx vs MixinBuilder
706 772
@@ -111,7 +111,7 @@ class GetMaterialApp extends StatelessWidget { @@ -111,7 +111,7 @@ class GetMaterialApp extends StatelessWidget {
111 final ThemeData highContrastDarkTheme; 111 final ThemeData highContrastDarkTheme;
112 final Map<Type, Action<Intent>> actions; 112 final Map<Type, Action<Intent>> actions;
113 final bool debugShowMaterialGrid; 113 final bool debugShowMaterialGrid;
114 - final Function(Routing) routingCallback; 114 + final ValueChanged<Routing> routingCallback;
115 final Transition defaultTransition; 115 final Transition defaultTransition;
116 final bool opaqueRoute; 116 final bool opaqueRoute;
117 final VoidCallback onInit; 117 final VoidCallback onInit;
@@ -198,8 +198,10 @@ class GetMaterialApp extends StatelessWidget { @@ -198,8 +198,10 @@ class GetMaterialApp extends StatelessWidget {
198 initialRoute = null, 198 initialRoute = null,
199 super(key: key); 199 super(key: key);
200 200
201 - Route<dynamic> generator(RouteSettings settings) =>  
202 - PageRedirect(settings, unknownRoute).page(); 201 + Route<dynamic> generator(RouteSettings settings) {
  202 + print(settings.name);
  203 + return PageRedirect(settings, unknownRoute).page();
  204 + }
203 205
204 List<Route<dynamic>> initialRoutesGenerate(String name) => 206 List<Route<dynamic>> initialRoutesGenerate(String name) =>
205 [PageRedirect(RouteSettings(name: name), unknownRoute).page()]; 207 [PageRedirect(RouteSettings(name: name), unknownRoute).page()];
@@ -132,7 +132,7 @@ extension StateExt<T> on StateMixin<T> { @@ -132,7 +132,7 @@ extension StateExt<T> on StateMixin<T> {
132 assert(widget != null); 132 assert(widget != null);
133 return SimpleBuilder(builder: (_) { 133 return SimpleBuilder(builder: (_) {
134 if (status.isLoading) { 134 if (status.isLoading) {
135 - return onLoading ?? Center(child: CircularProgressIndicator()); 135 + return onLoading ?? const Center(child: CircularProgressIndicator());
136 } else if (status.isError) { 136 } else if (status.isError) {
137 return onError != null 137 return onError != null
138 ? onError(status.errorMessage) 138 ? onError(status.errorMessage)