update method
void
update([
- T copy(
- T
- RouteInformation? routeInformation,
- BeamParameters? beamParameters,
- bool rebuild = true,
- bool tryPoppingHistory = true,
Updates the state and history, depending on inputs.
If copy
function is provided, state should be created from given current state.
New routeInformation
gets added to history.
If copy
is null
, then routeInformation
is used, either null
or not.
If routeInformation
is null
, then the state will upadate from
last history element and nothing shall be added to history.
Else, the state updates from available routeInformation
.
See updateState and addToHistory.
Implementation
void update([
T Function(T)? copy,
RouteInformation? routeInformation,
BeamParameters? beamParameters,
bool rebuild = true,
bool tryPoppingHistory = true,
]) {
if (copy != null) {
state = copy(state);
addToHistory(
state.routeInformation,
beamParameters ?? const BeamParameters(),
tryPoppingHistory,
);
} else {
if (routeInformation == null) {
updateState(history.last.routeInformation);
} else if (routeInformation.uri == state.routeInformation.uri) {
// if the new route information is the same as in the state it means
// the state changed first and notified listeners, so updating it
// will be unnecessary. Let's just add route to history with [tryPoppingHistory] set to true
addToHistory(
state.routeInformation,
beamParameters ?? const BeamParameters(),
);
} else {
updateState(routeInformation);
addToHistory(
state.routeInformation,
beamParameters ?? const BeamParameters(),
tryPoppingHistory,
);
}
}
onUpdate();
if (rebuild) {
notifyListeners();
}
}