navigatePushRemoveUntil method

void navigatePushRemoveUntil({
  1. required BuildContext context,
  2. required Widget pageToNavigate,
  3. required String routeName,
  4. dynamic onNavigateComplete()?,
})

Implementation

void navigatePushRemoveUntil(
    {required BuildContext context,
    required Widget pageToNavigate,
    required String routeName,
    Function()? onNavigateComplete}) {
  // Navigate to the new route (simulated navigation)
  currentRoute = routeName;
  debugPrint("Navigating to $routeName");
  // Push the current route to the history before navigating
  if (currentRoute != null) {
    debugPrint("Adding the current route");
    routeHistory.add(currentRoute!);
  } else {
    debugPrint("current route is null not adding the history");
  }
  Navigator.of(context)
      .pushAndRemoveUntil(
        MaterialPageRoute(
          builder: (context) => pageToNavigate,
        ),
        (route) => false,
      )
      .then((value) => onNavigateComplete?.call());
}