pushReplacement method

void pushReplacement(
  1. Widget page, {
  2. bool fullscreen = false,
})

Replaces the current page with a new page.

Clears the entire navigation history and sets the given page as the only page in the stack. This is useful for scenarios like login/logout where you want to reset the navigation state.

Implementation

void pushReplacement(Widget page, {bool fullscreen = false}) {
  setState(() {
    _dynamicHistory.clear();
    if (_fullscreen || fullscreen) {
      _dynamicHistory.add(page);
      _fullscreen = true;
    }
    if (_dynamicHistory.isEmpty) {
      _fullscreen = false;
    }
    _navRailKey.currentState?.setSecondaryActions([]);
    _history.clear();
    _history.add(page);
    _selectedIndex = _history.length - 1;
  });
}