toAndClearAll method

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

Navigates to the specified route and clears all previous routes.

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

Implementation

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