GetX key points after one-month of coding
GetxController
OK, so at the first, you need to know that every core functions for your data have to be inside of a class.
They call that class a controller
.
It may look like this:
class MyMoneyDataController extends GetxController {
}
Rx**
Then you need to have some variables to work with.
You put all of your variables into the Controller class
you have.
For example:
class MyMoneyDataController extends GetxController {
RxMap<String, String> yourMap = RxMap<String, String>();
}
No matter what data type you have, you shall always wrap it with Rx**
.
Rx here means Observable x variable
. (I know it sounds ridiculous and they are not relevant, but that’s how they define it)
For example, list
When you create one, you use:
RxList yourList = RxList([]);
// RxList yourList = ["default value"].obs; // I don't like this way, because it can't have an empty list.
When you use one, you use:
yourList.toList();
Trust me, if you do not follow my example, you’ll get fucked someday.
For example, an arbitrary variable
When you create one, you use:
Rx<YourObject> yourObject = Rx<YourObject>(YourObject());
When you use one, you use:
YourObject.value;
Obx
Only have the Rx Value
won’t let you refresh your UI in real-time.
You have to use Obx
.
There should at least have one Rx Value
been used under the Obx widget
.
Here’s how you define it:
Obx(() => SomeStupidWidget(value: YourRxList.toList()))
or
Obx(() {
// you could also use your rx variable here.
return SomeStupidWidget(value: YourRxList.toList()));
})
The author
yingshaoxo@gmail.com
https://yingshaoxo.blogspot.com/2021/07/getx-key-points-after-one-month-of.html