1

Assume the previous route is A and the current route is B.

First, we stay on route A.

the previous route is null
the current route is A

Then, we open route B.

the previous route is A
the current route is B

After that, we opened a dialog and closed it. These routes should have the same route as above. But in real life.

the previous route is B
the current route is B

See the video: The video here.

Try it: The web for this video

This makes me can not work. example: Can not open a dialog again or check whether the previous route is empty or not.

I think the GetX thinks a dialog is a new route. So, GetX tries to change the previous route to this route and the current route tries to change the route for this dialog. But this route's name didn't define. So, the current route changed to the same route.

For using ModalRoute.of(context)!.settings.name, this is working successfully but this can't use with Get.context. I think it is a bug. I have posted this bug on Github. But I have to work now.

I want to check if the previous route is empty. Then change the Get.back() to Get.toName()(If previous route is empty then go to specific route). Is there any way to prevent this?

1 Answers1

0

I came back to think of what I wanted. If the previous route is empty then go to the specific route.

From another perspective on this point, this means if the previous route is empty, the Get.back() will not work. Then the previous route and current route still same value.

So, I can check this by using:

void getBack(url) {
  String previousRoute = Get.previousRoute, currentRoute = Get.currentRoute;
  Get.back();
  if (url is String && previousRoute == Get.previousRoute && currentRoute == Get.currentRoute) Get.offNamed(url);
}

But this is still a problem.