UseState<T> class

A ReactterHook that manages a state.

Contains a value of type T which represents the current state.

When value is different to previous state, UseState execute update to notify container instance that has changed and in turn executes onWillUpdate and onDidUpdate.

This example produces one simple UseState:

class AppController {
  late final likesCount = UseState(0, this);
  late final followed = UseState(false, this);
  late final text = UseState("", this);
  late final user = UseState<User?>(null, this);
  late final posts = UseState(<Post>[], this);

  AppController() {
    likesCount.value += 1;
    followed.value = followed.value!;
    text.value = "This is a text";
    user.value = User(name: "name");

    // It's need to force [update] because mantain the previous state
    // and the [context] not aware that this state has changed
    posts.update(() {
      posts.value.add(
          Post(
            user: user.value,
            text: text.value,
          ),
        );
    });
  }
}
Inheritance

Constructors

UseState(T initialValue)
A ReactterHook that manages a state.

Properties

$ → HookRegister
This variable is used to register Hook and attach the StateBase that are defined here.
final
eventManager → EventManager
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
instanceBinded Object?
The reference instance to the current state.
no setterinherited
instanceManager → InstanceManager
no setterinherited
isDisposed bool
Returns true if the state has been disposed.
no setterinherited
logger → Logger
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateManager → StateManager<StateBase>
no setterinherited
value ↔ T
Get current value state
getter/setter pair

Methods

bind(Object instance) → void
Stores a reference to an object instance
inherited
dispose() → void
Called when this object is removed
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh() → void
It's used to notify listeners that the state has been updated. It is typically called after making changes to the state object.
inherited
toString() String
A string representation of this object.
inherited
unbind() → void
Removes the reference to the object instance
inherited
update([covariant Function? callback]) → void
Executes callback, and notifies the listeners about the update.
inherited

Operators

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