class UserController extends GetxController{
RxInt count=0.obs;
void increment(){
count.value++;
update();
}
}
GetView 是 GetX 库中的一个用于构建视图的组件。它与一个注册的 Controller 关联,并通过 getter 方法提供对该 Controller 的访问。简单的说就是,GetView 简化了 GetX 中对 控制器的访问,GetView<自定义Controller>绑定控制器后可直接使用,避免了写 Get.Find()。
如果是依赖 GetxController,GetX 会自动管理它的生命周期。当这个依赖项被创建时,GetX会调用它的 onInit() 和 onReady()方法;当这个依赖项被删除时,GetX 会调用它的 onClose() 方法。