toClearAndPush function

void toClearAndPush(
  1. Widget page, {
  2. RouteSettings? settings,
})

Clear all existing routes and push the provided page onto the navigation stack, optionally with custom settings.

Example:

toClearAndPush(MyHomePage(), settings: RouteSettings(name: '/home'));

Implementation

void toClearAndPush(Widget page, {RouteSettings? settings}) {
  Navigator.of(Utils.navigatorKey.currentContext!).pushAndRemoveUntil(
    MaterialPageRoute(builder: (context) => page, settings: settings),
    (route) => false,
  );
}