replace method

Future<void> replace(
  1. Widget screen, {
  2. bool transparent = false,
  3. bool isCupertino = false,
})

Replace the current route of the navigator by pushing the given route and then disposing the previous route.

Implementation

Future<void> replace(
  Widget screen, {
  bool transparent = false,
  bool isCupertino = false,
}) {
  RouteSettings settings = RouteSettings(
    name: screen.toString(),
  );
  if (transparent) {
    // ignore: always_specify_types
    return Navigator.of(this).pushReplacement(
      TransparentRoute(
        builder: (_) => screen,
        settings: settings,
      ),
    );
  } else {
    if (isCupertino) {
      // ignore: always_specify_types
      return Navigator.of(this).pushReplacement(
        CupertinoPageRoute(
          builder: (_) => screen,
          settings: settings,
        ),
      );
    }
    // ignore: always_specify_types
    return Navigator.of(this).pushReplacement(
      MaterialPageRoute(
        builder: (_) => screen,
        settings: settings,
      ),
    );
  }
}