setState method
void
setState(
- BaseAsyncState<
S> next, { - bool notify = true,
- bool forced = false,
- bool equalityCheck(
- S? curr,
- S? next
Updates the state with the given next
state.
next
is the new state to set.
notify
(default: true): Controls whether listeners are notified and the UI is rebuilt.
forced
(default: false): Forces the state update even if the value hasn't changed.
equalityCheck
(optional): Custom function to determine if state has changed.
This method provides fine-grained control over state updates and listener notifications.
Example:
void updateState(BaseAsyncState<String> newState) {
setState(newState, notify: true, forced: false);
}
Implementation
@protected
void setState(
BaseAsyncState<S> next, {
bool notify = true,
bool forced = false,
bool Function(S? curr, S? next)? equalityCheck,
}) {
_setState(
next,
notify: notify,
forced: forced,
onUpdate: onUpdate,
equalityCheck: (curr, next) =>
(equalityCheck?.call(curr.data, next.data) ??
this.stateEqualityCheck(curr, next)) &&
curr == next,
);
}