toAndClearAll method

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

Navigates to the specified route and removes all other routes from the stack.

If a valid BuildContext and routeName are provided, this method navigates to the specified route and clears all other routes from the stack, making it the only route in the navigation stack.

Implementation

void toAndClearAll({String? routeName, Map<String,dynamic>? args}) {
  if (routeName != null) {
    Navigator.of(context).pushNamedAndRemoveUntil(routeName, (_) => false,
        arguments: args);
  }
}