toPushAndClearAll function

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

Push the provided page onto the navigation stack and remove all routes until a specified predicate is met.

Example:

toPushAndClearAll(MyPage(), settings: RouteSettings(name: '/newPage'));

Implementation

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