LevitController class abstract

A base class for business logic components.

LevitController manages the lifecycle of application logic, providing automated resource cleanup and integration with the dependency injection system.

Implementers should override onInit for setup and onClose for cleanup. Use autoDispose to simplify resource management.

// Example usage:

class CounterController extends LevitController {
  final count = 0.lx;

  @override
  void onInit() {
    autoDispose(count); // Cleanup on close
  }
}

Prefer LxWorker + autoDispose for reload / reaction side effects instead of raw .stream.listen:

autoDispose(LxWorker(contextVar, (_) async {
  await reload();
}));

LxWorker is an LxReactive, so autoDispose closes it with the controller.

Lifecycle:

  1. Construction: Instance created.
  2. Attachment: Linked to a LevitScope.
  3. Initialization: onInit called.
  4. Disposal: onClose called when scope closes.
Inheritance
Mixed-in types
Implementers

Constructors

LevitController()

Properties

disposed Future<void>
Completes when cleanup reaches its terminal state.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
initialized bool
Whether onInit has been executed.
no setter
isClosed bool
Whether the controller has been disposed and closed.
no setter
isClosing bool
Whether owner cleanup has started.
no setterinherited
isDisposed bool
Whether cleanup has completed.
no setterinherited
isInitialized bool
Whether the initialization phase is complete.
no setter
ownedResources Iterable<Object>
Resources currently tracked by this owner.
no setterinherited
ownerPath String
The full owner path within the monitoring system (scopeId:registrationKey).
no setter
registrationKey String?
The registration key used to identify this instance in Levit.
no setter
resourceOwnerPath String
A diagnostic owner path applied to otherwise unnamed reactive resources.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scope LevitScope?
The LevitScope that currently owns this controller.
no setter

Methods

autoDispose<T>(T object) → T
Registers object for automatic cleanup when the controller closes.
override
didAttachToScope(LevitScope scope, {String? key}) → void
Attaches this controller to an owning scope with an optional registration key.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onClose() FutureOr<void>
Called when the controller is removed from memory.
override
onInit() → void
Called immediately after the controller is initialized.
override
own<T>(T resource) → T
Registers resource for deterministic cleanup and returns it.
inherited
refreshOwnedReactivePaths() → void
Reconciles already-owned reactive diagnostics after scope attachment.
inherited
runGuardedAsync<T>(FutureOr<T> action(), {bool cancelOnClose = true, void onError(Object error, StackTrace stackTrace)?}) Future<T?>
Executes action and suppresses its result if this controller closes first.
toString() String
A string representation of this object.
inherited

Operators

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