jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.36k stars 1.63k forks source link

The problem of duplicate routing pages #2751

Open chenjiangmin126 opened 1 year ago

chenjiangmin126 commented 1 year ago

Describe I want to know about routing management. How to achieve this requirement? There are scenarios where multiple product details are opened during app operation. I have multiple product detail pages, and each product detail page will have an ID passed as a parameter. "I want to delete the old page and reopen a new one when the product page with this ID was previously opened.". If the product ID does not exist in the routing record. Open a new page directly.

Currently, I set different "tag" for the controller when routing jumps. But they keep opening a new page, even when the “tag” are the same, My goal is to close the previously opened page when the “tag” is the same

example:

String tag = "dynamicPhoto$id";
Get.to(
    () => DynamicPhotoPage(tag: tag),
    arguments: {"id": id},
    binding: DynamicPhotoBinding(tag: tag),
    routeName: tag,
    preventDuplicates: false,
);

Flutter Version: 3.3.3

Getx Version: 4.6.5

jonataslaw commented 1 year ago

Instead of Get.to you can use Get.off (to remove current page)

Named routes are better to this usecase to. You can set the parameters by route

chenjiangmin126 commented 1 year ago

@jonataslaw Thank you for your reply

I will not close the current page to jump to a new page. Conversely, when opening a new page, can I close the page in the routing record?

For example, pageA ->pageB ->PageC ->PageD Close PageC when I want to open PagE.

LUK3D commented 1 year ago

@chenjiangmin126 You can achieve this by adding a unique tag on your details page controller. This way every time you open that page, it will create a new instance instead of using the old one.

chenjiangmin126 commented 1 year ago

@LUK3D Yes, my details page controller uses tag I want to close the previously existing page if I repeatedly open it. For example, my controller tag is, detail 1 -> detail 2 -> detail_ 3 When I was at detail_3 Open the detail1, the first detail The details page for 1 closes. Reopen a detail_1 Page