pushReplacement<T extends Object?> method

Future<T> pushReplacement<T extends Object?>(
  1. Widget screen, {
  2. RouteSettings? settings,
  3. bool maintainState = true,
  4. bool fullscreenDialog = false,
  5. bool rootNavigator = false,
  6. dynamic result,
})

Replaces the current route with a new screen.

Allows customization of the route via settings, maintainState, and fullscreenDialog. rootNavigator determines whether to push the route onto the root navigator or the nearest Navigator ancestor.

Optionally returns a result to the previous route.

Returns a Future that completes with the result of the pushed route when it is popped.

Implementation

Future<T> pushReplacement<T extends Object?>(
  Widget screen, {
  RouteSettings? settings,
  bool maintainState = true,
  bool fullscreenDialog = false,
  bool rootNavigator = false,
  dynamic result,
}) async =>
    await Navigator.of(
      this,
      rootNavigator: rootNavigator,
    ).pushReplacement(
      MaterialPageRoute(
        builder: (_) => screen,
        settings: settings,
        maintainState: maintainState,
        fullscreenDialog: fullscreenDialog,
      ),
      result: result,
    );