JController<T extends JState> class abstract

Base controller for managing state and side effects in a reactive architecture.

JController extends StateNotifier<T> to provide controlled state management, and introduces support for handling one-time UI effects through a side effect stream.

It is designed to work with JState and JIntent, promoting a clean separation of UI, state, and side-effect logic.

Example usage:

class LoginController extends JController<LoginState> {
  LoginController() : super(LoginState.initial());

  Future<void> login(String user, String pass) async {
    setState(state.copyWith(loading: true));
    final success = await someLoginUseCase(user, pass);
    if (!success) {
      emitSideEffect(ShowLoginError(message: "Login failed"));
    }
    setState(state.copyWith(loading: false));
  }
}
Inheritance
  • Object
  • StateNotifier<T>
  • JController

Constructors

JController(T initialState)
Creates a new JController with the given initial state.

Properties

currentState → T
Returns the current state of type T.
no setter
debugState → T
A development-only way to access state outside of StateNotifier.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
If a listener has been added using addListener and hasn't been removed yet.
no setterinherited
mounted bool
Whether dispose was called or not.
no setterinherited
onError ↔ ErrorListener?
A callback for error reporting if one of the listeners added with addListener throws.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sideEffects Stream<JEffect>
Stream of side effects emitted by the controller.
no setter
state ↔ T
The current "state" of this StateNotifier.
getter/setter pairinherited
stream Stream<T>
A broadcast stream representation of a StateNotifier.
no setterinherited

Methods

addListener(Listener<T> listener, {bool fireImmediately = true}) → RemoveListener
Subscribes to this object.
inherited
dispose() → void
Frees all the resources associated with this object.
override
emitAndWaitSideEffect<V>(JEffect<V> effect) Future<V>
Emits a side effect and waits for the result.
emitSideEffect(JEffect effect) → void
Emits a one-time JEffect to the UI.
intent(JIntent<T> intent) Future<void>
Handles a given JIntent to update the state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onInit() → void
Initialization lifecycle method.
setState(T newState) → void
Sets a new state of type T if different from the current state.
toString() String
A string representation of this object.
inherited
updateShouldNotify(T old, T current) bool
Whether to notify listeners or not when state changes
inherited

Operators

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