Docs mirror / State management

GetX state management docs, restored.

The same controller-first state model teams already know: reactive values, simple state updates, and lifecycle hooks.

Reactive state

Use .obs with Obx for fine-grained UI updates.

This is the most recognizable GetX state pattern. The value becomes observable with .obs, and the widget listens with Obx.

Reactive example

counter_controller.dart

class CounterController extends GetxController {
  final count = 0.obs;

  void increment() {
    count.value++;
  }
}

UI binding

counter_view.dart

final controller = Get.put(CounterController());

Obx(() => Text('${controller.count.value}'));

Simple state

Use GetBuilder when you want explicit updates.

GetBuilder is useful when you want simpler rebuild control and do not need reactive streams for every property.

GetBuilder example

cart_controller.dart

class CartController extends GetxController {
  var total = 0;

  void addItem(int price) {
    total += price;
    update();
  }
}

Controller lifecycle

Keep setup and cleanup inside the controller.

onInit, onReady, and onCloseremain important when restoring older GetX applications.

Lifecycle hooks

profile_controller.dart

class ProfileController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    fetchProfile();
  }

  @override
  void onClose() {
    disposeStreams();
    super.onClose();
  }
}