Committed by
GitHub
Merge pull request #530 from roipeker/docs
docs changes
Showing
2 changed files
with
41 additions
and
2 deletions
@@ -81,7 +81,7 @@ import 'package:get/get.dart'; | @@ -81,7 +81,7 @@ import 'package:get/get.dart'; | ||
81 | 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. | 81 | 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. |
82 | 82 | ||
83 | - Step 1: | 83 | - Step 1: |
84 | -Add "Get" before your materialApp, turning it into GetMaterialApp | 84 | +Add "Get" before your MaterialApp, turning it into GetMaterialApp |
85 | 85 | ||
86 | ```dart | 86 | ```dart |
87 | void main() => runApp(GetMaterialApp(home: Home())); | 87 | void main() => runApp(GetMaterialApp(home: Home())); |
@@ -498,6 +498,43 @@ void localLogWriter(String text, {bool isError = false}) { | @@ -498,6 +498,43 @@ void localLogWriter(String text, {bool isError = false}) { | ||
498 | 498 | ||
499 | ``` | 499 | ``` |
500 | 500 | ||
501 | +### Local State Widgets | ||
502 | + | ||
503 | +These Widgets allows you to manage a single value, and keep the state ephemeral and locally. | ||
504 | +We have flavours for Reactive and Simple. | ||
505 | +For instance, you might use them to toggle obscureText in a TextField, maybe create a custom | ||
506 | +Expandable Panel, or maybe modify the current index in BottomNavigationBar while changing the content | ||
507 | +of the body in a Scaffold. | ||
508 | + | ||
509 | +#### ValueBuilder | ||
510 | +A simplification of StatefulWidget that works with a "setState" callback that takes the updated value. | ||
511 | + | ||
512 | +```dart | ||
513 | +ValueBuilder<bool>( | ||
514 | + initialValue: false, | ||
515 | + builder: (value, updateFn) => Switch( | ||
516 | + value: value, | ||
517 | + onChanged: updateFn, // same signature! you could use ( newValue ) => updateFn( newValue ) | ||
518 | + ), | ||
519 | + // if you need to call something outside the builder method. | ||
520 | + onUpdate: (value) => print("Value updated: $value"), | ||
521 | + onDispose: () => print("Widget unmounted"), | ||
522 | +), | ||
523 | +``` | ||
524 | + | ||
525 | +#### ObxValue | ||
526 | +Similar to ValueBuilder, but this is the Reactive version, you pass a Rx instance (remember the magical .obs?) and | ||
527 | +updates automatically... isn't it awesome? | ||
528 | + | ||
529 | +```dart | ||
530 | +ObxValue((data) => Switch( | ||
531 | + value: data.value, | ||
532 | + onChanged: data, // Rx has a _callable_ function! You could use (flag) => data.value = flag, | ||
533 | + ), | ||
534 | + false.obs, | ||
535 | +), | ||
536 | +``` | ||
537 | + | ||
501 | ## Video explanation of Other GetX Features | 538 | ## Video explanation of Other GetX Features |
502 | 539 | ||
503 | 540 |
@@ -11,7 +11,8 @@ typedef ValueBuilderBuilder<T> = Widget Function( | @@ -11,7 +11,8 @@ typedef ValueBuilderBuilder<T> = Widget Function( | ||
11 | 11 | ||
12 | /// Manages a local state like ObxValue, but uses a callback instead of a Rx value. | 12 | /// Manages a local state like ObxValue, but uses a callback instead of a Rx value. |
13 | /// | 13 | /// |
14 | -/// Sample: | 14 | +/// Example: |
15 | +/// ``` | ||
15 | /// ValueBuilder<bool>( | 16 | /// ValueBuilder<bool>( |
16 | /// initialValue: false, | 17 | /// initialValue: false, |
17 | /// builder: (value, update) => Switch( | 18 | /// builder: (value, update) => Switch( |
@@ -21,6 +22,7 @@ typedef ValueBuilderBuilder<T> = Widget Function( | @@ -21,6 +22,7 @@ typedef ValueBuilderBuilder<T> = Widget Function( | ||
21 | /// },), | 22 | /// },), |
22 | /// onUpdate: (value) => print("Value updated: $value"), | 23 | /// onUpdate: (value) => print("Value updated: $value"), |
23 | /// ), | 24 | /// ), |
25 | +/// ``` | ||
24 | class ValueBuilder<T> extends StatefulWidget { | 26 | class ValueBuilder<T> extends StatefulWidget { |
25 | final T initialValue; | 27 | final T initialValue; |
26 | final ValueBuilderBuilder builder; | 28 | final ValueBuilderBuilder builder; |
-
Please register or login to post a comment