navigateTo method

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

Implementation

void navigateTo({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).push(MaterialPageRoute(
    builder: (context) => pageToNavigate,
  )).then((_) {
    // Execute the callback when navigation is complete if provided
    onNavigateComplete?.call();
  });
}