addToHistory method

void addToHistory(
  1. RouteInformation routeInformation, [
  2. BeamParameters beamParameters = const BeamParameters(),
  3. bool tryPopping = true
])

Adds another HistoryElement to history list. The history element is created from given state and beamParameters.

If tryPopping is set to true, the state with the same location will be searched in history and if found, entire history segment [foundIndex, history.length-1] will be removed before adding a new history element.

Implementation

void addToHistory(
  RouteInformation routeInformation, [
  BeamParameters beamParameters = const BeamParameters(),
  bool tryPopping = true,
]) {
  if (tryPopping) {
    final sameStateIndex = history.indexWhere((element) {
      return element.routeInformation.uri == state.routeInformation.uri;
    });
    if (sameStateIndex != -1) {
      history.removeRange(sameStateIndex, history.length);
    }
  }
  if (history.isEmpty ||
      routeInformation.uri != history.last.routeInformation.uri) {
    history.add(HistoryElement(routeInformation, beamParameters));
  }
}