ReactiveController class abstract

Base class for reactive controllers with lifecycle management.

ReactiveController provides a structured lifecycle for managing business logic and state in your application. It integrates with ReactiveState for automatic dependency injection and cleanup.

Lifecycle methods:

  1. Constructor - Controller is created
  2. onInit - Called immediately after construction
  3. onReady - Called when widget tree is fully built (after first frame)
  4. onClose - Called before controller disposal

Example:

class CounterController extends ReactiveController {
  final count = Reactive<int>(0);
  late StreamSubscription _subscription;

  @override
  void onInit() {
    super.onInit();
    print('Controller initialized');
  }

  @override
  void onReady() {
    super.onReady();
    // Safe to access context-dependent resources here
    _subscription = someStream.listen((data) {
      count.value = data;
    });
  }

  void increment() => count.value++;

  @override
  void onClose() {
    _subscription.cancel();
    count.close();
    super.onClose();
  }
}

Constructors

ReactiveController()
Creates a ReactiveController and calls onInit.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onClose() → void
Lifecycle method called before controller disposal.
onInit() → void
Lifecycle method called immediately after controller creation.
onReady() → void
Lifecycle method called after the widget tree is fully built.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited