removeLocalHistoryEntry method

void removeLocalHistoryEntry(
  1. LocalHistoryEntry entry
)

Remove a local history entry from this route.

The entry's LocalHistoryEntry.onRemove callback, if any, will be called synchronously.

Implementation

void removeLocalHistoryEntry(LocalHistoryEntry entry) {
  assert(entry._owner == this);
  assert(_localHistory!.contains(entry));
  bool internalStateChanged = false;
  if (_localHistory!.remove(entry) && entry.impliesAppBarDismissal) {
    _entriesImpliesAppBarDismissal -= 1;
    internalStateChanged = _entriesImpliesAppBarDismissal == 0;
  }
  entry._owner = null;
  entry._notifyRemoved();
  if (_localHistory!.isEmpty || internalStateChanged) {
    assert(_entriesImpliesAppBarDismissal == 0);
    if (SchedulerBinding.instance.schedulerPhase == SchedulerPhase.persistentCallbacks) {
      // The local history might be removed as a result of disposing inactive
      // elements during finalizeTree. The state is locked at this moment, and
      // we can only notify state has changed in the next frame.
      SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
        if (isActive) {
          changedInternalState();
        }
      }, debugLabel: 'LocalHistoryRoute.changedInternalState');
    } else {
      changedInternalState();
    }
  }
}