replaceWithNamedRoute method

void replaceWithNamedRoute(
  1. String routeName, {
  2. Map<String, dynamic>? args,
})

Replaces the current route with a named route.

routeName is the name of the new route. args are the optional arguments to pass to the route.

Implementation

void replaceWithNamedRoute(String routeName, {Map<String, dynamic>? args}) {
  try {
    if (context != null) {
      Navigator.pushReplacementNamed(context!, routeName, arguments: args);
    } else if (navigatorKey != null) {
      navigatorKey!.currentState!
          .pushReplacementNamed(routeName, arguments: args);
    }
  } catch (e) {
    print('Error in replaceWithNamedRoute: $e');
  }
}