navigatePushReplacement method

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

Implementation

void navigatePushReplacement({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.removeLast();
    routeHistory.add(currentRoute!);
  } else {
    debugPrint("current route is null not adding the history");
  }
  Navigator.of(context).pushReplacement(
    MaterialPageRoute(
      builder: (context) => pageToNavigate,
    ),
  ).then((value) => onNavigateComplete?.call());
}