transformStateSilently method
Transforms the current entire AsyncState using the provided transformer
function, without notifying listeners.
This is the "silent" version of transformState. It's useful for making complex internal state transitions (e.g., from loading to error, or modifying data within a success state) that should not immediately trigger a UI rebuild or other listener-driven side effects.
The transformer function receives the current AsyncState<T> and should
return a new AsyncState<T>.
Example:
// Silently change state to error if data is null during an internal check
transformStateSilently((currentState) {
if (currentState.isSuccess && currentState.data == null) {
return AsyncState.error('Internal check: Data became null');
}
return currentState;
});
- Parameter transformer: A function that takes the current [AsyncState<T>]
and returns a new [AsyncState<T>].
Implementation
void transformStateSilently(
AsyncState<T> Function(AsyncState<T> state) transformer,
) {
final previous = _state;
_state = transformer(_state);
// Execute async state change hook (even for silent updates)
onAsyncStateChanged(previous, _state);
}