pushReplacement<T> method

Future<T?> pushReplacement<T>(
  1. Route route, [
  2. Object? result
])

Replaces the top route with the given route, then pushes it.

Returns a future that completes with the pop result.

Implementation

Future<T?> pushReplacement<T>(Route route, [Object? result]) {
  final completer = Completer<T?>();
  final oldRoute = currentRoute;
  setState(() {
    if (_history.isNotEmpty) {
      _removeLast(result);
    }
    _addRoute(route, completer);
  });
  if (route.fullScreenRender) {
    WidgetsBinding.instance.scheduleFrameWithClear();
  } else {
    WidgetsBinding.instance.scheduleFrame();
  }
  _notifyObservers(
    (observer) => observer.didReplace(newRoute: route, oldRoute: oldRoute),
  );
  return completer.future;
}