You can also use Get.generalDialog instead of showGeneralDialog.
...
...
@@ -248,24 +250,23 @@ Get.bottomSheet is like showModalBottomSheet, but don't need of context.
```dart
Get.bottomSheet(
Container(
child:Wrap(
children:<Widget>[
ListTile(
leading:Icon(Icons.music_note),
title:Text('Music'),
onTap:()=>{}
),
ListTile(
leading:Icon(Icons.videocam),
title:Text('Video'),
onTap:()=>{},
),
],
Container(
child:Wrap(
children:<Widget>[
ListTile(
leading:Icon(Icons.music_note),
title:Text('Music'),
onTap:()=>{}
),
);
}
);
ListTile(
leading:Icon(Icons.videocam),
title:Text('Video'),
onTap:()=>{},
),
],
),
);
);
```
## Simple State Manager
...
...
@@ -312,10 +313,11 @@ class Controller extends GetController {
}
// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called
GetBuilder<Controller>(
init:Controller(),// INIT IT ONLY THE FIRST TIME
builder:(_)=>Text(
'${_.counter}',
)),
init:Controller(),// INIT IT ONLY THE FIRST TIME
builder:(_)=>Text(
'${_.counter}',
),
)
//Initialize your controller only the first time. The second time you are using ReBuilder for the same controller, do not use it again. Your controller will be automatically removed from memory as soon as the widget that marked it as 'init' is deployed. You don't have to worry about that, Get will do it automatically, just make sure you don't start the same controller twice.
```
**Done!**
...
...
@@ -327,7 +329,7 @@ GetBuilder<Controller>(
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):
```dart
classOtherClasseextendsStatelessWidget{
classOtherClassextendsStatelessWidget{
@override
Widgetbuild(BuildContextcontext){
returnScaffold(
...
...
@@ -361,11 +363,11 @@ class Controller extends GetController {
And then you can access your controller directly, that way:
```dart
FloatingActionButton(
onPressed:(){
Controller.to.increment(),
}// This is incredibly simple!
child:Text("${Controller.to.counter}"),
),
onPressed:(){
Controller.to.increment(),
}// This is incredibly simple!
child:Text("${Controller.to.counter}"),
),
```
When you press FloatingActionButton, all widgets that are listening to the 'counter' variable will be updated automatically.
...
...
@@ -379,10 +381,10 @@ If you need to call initState() or dispose() method for example, you can call th
```dart
GetBuilder<Controller>(
initState(_)=>Controller.to.fetchApi(),
dispose(_)=>Controller.to.closeStreams(),
builder:(s)=>Text('${s.username}'),
),
initState:(_)=>Controller.to.fetchApi(),
dispose:(_)=>Controller.to.closeStreams(),
builder:(s)=>Text('${s.username}'),
),
```
A much better approach than this is to use the onInit() and onClose() method directly from your controller.
...
...
@@ -406,17 +408,17 @@ Do not call a dispose method inside GetController, it will not do anything, reme
You can use Controller instance directly on GetBuilder value:
```dart
GetBuilder<Controller>(
init:Controller(),
builder:(value)=>Text(
'${value.counter}',//here
)),
GetBuilder<Controller>(
init:Controller(),
builder:(value)=>Text(
'${value.counter}',//here
),
),
```
You may also need an instance of your controller outside of your GetBuilder, and you can use these approaches to achieve this:
...
...
@@ -445,35 +448,38 @@ class Controller extends GetController {
}
// on stateful/stateless class
GetBuilder<Controller>(
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Controller.to.counter}',//here
)),
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Controller.to.counter}',//here
)
),
```
or
```dart
classControllerextendsGetController{
// static Controller get to => Get.find(); // with no static get
[...]
}
// on stateful/stateless class
GetBuilder<Controller>(
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Get.find<Controller>().counter}',//here
)),
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Get.find<Controller>().counter}',//here
),
),
```
- 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:
```dart
Controllercontroller=Controller();
[...]
GetBuilder(// you dont need to type on this way
init:controller,//here
builder:(_)=>Text(
'${controller.counter}',// here
)),
init:controller,//here
builder:(_)=>Text(
'${controller.counter}',// here
),
),
```
This approach is not recommended, as you will have to manually dispose of your controllers, close your streams manually, and literally give up one of the great benefits of this library, which is intelligent memory control. But if you trust your potential, go ahead!
...
...
@@ -481,11 +487,12 @@ This approach is not recommended, as you will have to manually dispose of your c
If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs:
```dart
GetBuilder<Controller>(
id:'text'
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Get.find<Controller>().counter}',//here
)),
id:'text'
init:Controller(),// use it only first time on each controller
builder:(_)=>Text(
'${Get.find<Controller>().counter}',//here
),
),
```
And update it this form:
```dart
...
...
@@ -522,24 +529,24 @@ int get sum => count1.value + count2.value;
```
```dart
GetX<Controller>(
builder:(_){
print("count 1 rebuild");
returnText('${_.count1.value}');
},
),
GetX<Controller>(
builder:(_){
print("count 2 rebuild");
returnText('${_.count2.value}');
},
),
GetX<Controller>(
builder:(_){
print("count 3 rebuild");
returnText('${_.sum}');
},
),
GetX<Controller>(
builder:(_){
print("count 1 rebuild");
returnText('${_.count1.value}');
},
),
GetX<Controller>(
builder:(_){
print("count 2 rebuild");
returnText('${_.count2.value}');
},
),
GetX<Controller>(
builder:(_){
print("count 3 rebuild");
returnText('${_.sum}');
},
),
```
If we increment the number of count 1, only count 1 and count 3 are reconstructed, because count 1 now has a value of 1, and 1 + 0 = 1, changing the sum value.
...
...
@@ -615,8 +622,9 @@ You can access list.length, or list.value.length. Most of the time, both ways wi
finallist=List<User>().obs;
```
```dart
ListView.builder(
itemCount:list.value.lenght
ListView.builder(
itemCount:list.value.lenght
)
```
or else create a "get" method for it and abandon "value" for life. example: