pushAndRemoveUntil<T extends Object?> method

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

Pushes a new screen onto the navigator and removes all previous routes.

Allows customization of the route via settings, maintainState, and fullscreenDialog. routes determines if all routes should be removed. if set to true all routes will be removed, if false only the route before the pushed route will be removed. rootNavigator determines whether to push the route onto the root navigator or the nearest Navigator ancestor.

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

Implementation

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