setState method
void
setState(
- covariant dynamic newState, [
- dynamic callback()?
Triggers a rerender with new state obtained by shallow-merging newState
into the current state.
Optionally accepts a callback
that gets called after the component updates.
Also allows newState
to be used as a transactional setState
callback.
Implementation
void setState(covariant dynamic newState, [Function()? callback]) {
if (newState is Map) {
_nextState!.addAll(newState);
} else if (newState is StateUpdaterCallback) {
_transactionalSetStateCallbacks.add(newState);
} else if (newState != null) {
throw ArgumentError(
'setState expects its first parameter to either be a Map or a `TransactionalSetStateCallback`.');
}
if (callback != null) _setStateCallbacks.add(callback);
_jsRedraw();
}