0

I want to clear all previous routes in Getx. That's why I am using that function:

 static Future<void> removeAllAndNavigate(
    String nextScreen, {
    bool Function(Route<dynamic>)? predicate,
    dynamic arguments,
    int? id,
    Map<String, String>? parameters,   }) async {
    Get.offAllNamed(
      nextScreen,
      predicate: predicate,
      arguments: arguments,
      id: id,
      parameters: parameters,
    );   }

But today I realised that, it remember the previous route name. Cause after navigating new screen, I called

 print(Get.previousRoute);

and it show me previous route name. Where is the problem ?

Abir Ahsan
  • 2,649
  • 29
  • 51

1 Answers1

0

Use the Get.clearRouteTree(); method to remove all the routes and clear the route tree from the navigation stack. It will completely reset the navigation history and remove all the routes pushed or replaced onto the stack.

ElevatedButton(
  onPressed: () {
    // Clear the route tree and start with a new screen
    Get.clearRouteTree();
    Get.to(NewScreen());
  },
  child: const Text("Go to New Screen"),
),
Dharam Budh
  • 515
  • 2
  • 9