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
-
- Object
- ReactterHook
- UseState
Constructors
- UseState(T initial)
Properties
- $ → _HookRegister
-
This variable is used to register
ReacttrHookand attach the ReactterState that are defined here.final - hashCode → int
-
The hash code for this object.
no setterinherited
- initial ↔ T
-
The initial value in state.
getter/setter pair
- instanceAttached → Object?
-
no setterinherited
- isDisposed → bool
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ T
-
Get current value state
getter/setter pair
Methods
-
attachTo(
Object instance) → void -
Attaches an object instance to this state.
inherited
-
createState(
) → void -
Adds the current state to a list if instances of the Reactter class are being built.
inherited
-
detachInstance(
) → void -
Detaches an object instance to this state.
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 -
Forces update and notifies to listeners that it did update
inherited
-
reset(
) → void - Reset the state to initial value
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
[covariant Function? callback]) → void -
Executes
callback, and notify the listeners about to update.inherited -
updateAsync(
[covariant Function? callback]) → Future< void> -
Executes
callback, and notify the listeners about to update as async way.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited