toPushAndClearUntil function

void toPushAndClearUntil(
  1. Widget page,
  2. RoutePredicate predicate, {
  3. RouteSettings? settings,
})

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

Example:

toPushAndClearUntil(MyPage(), ModalRoute.withName('/dashboard'));

Implementation

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