beamBack method

bool beamBack({
  1. Object? data,
  2. bool replaceRouteInformation = false,
})

Beams to previous entry in beamingHistory. and removes the last entry from history.

If there is no previous entry, does nothing.

Returns the success, whether update was executed.

Implementation

bool beamBack({
  Object? data,
  bool replaceRouteInformation = false,
}) {
  if (!canBeamBack) {
    return false;
  }
  // first we try to beam back within last BeamLocation
  // i.e. we just pop its last history element id possible
  if (beamingHistory.last.history.length > 1) {
    beamingHistory.last.history.removeLast();
  } else {
    // here we know that beamingHistory.length > 1 (because of canBeamBack)
    // and that beamingHistory.last.history.length == 1
    // so this last (only) entry is removed along with BeamLocation
    _disposeBeamLocation(beamingHistory.last);
    beamingHistory.removeLast();
    _initBeamLocation(beamingHistory.last);
  }

  _beamLocationCandidate = beamingHistory.last;
  _beamLocationCandidate.update();
  final targetHistoryElement = _beamLocationCandidate.history.last;

  update(
    configuration: targetHistoryElement.routeInformation.copyWith(),
    beamParameters: targetHistoryElement.parameters.copyWith(
      transitionDelegate: beamBackTransitionDelegate,
    ),
    data: data,
    buildBeamLocation: false,
    replaceRouteInformation: replaceRouteInformation,
  );

  return true;
}