JaspervanRiet / duck_router

A Flutter router with intents
MIT License
4 stars 3 forks source link

Allow popping until a certain Location #7

Closed DelcoigneYves closed 3 months ago

DelcoigneYves commented 3 months ago

Hi there!

While there is already support to popping everything until the root Location, it would also be handy to pop until a certain Location is reached.

I believe it is already possible by executing this on the Navigator directly, but this won't work when dealing with nested navigation.

DelcoigneYves commented 3 months ago

Also related, it would be nice to be able to check if a certain Location was already in the current or parent stack.

JaspervanRiet commented 3 months ago

Do you have an example scenario where you would want to pop a number of routes below the current route, where .root() is not sufficient?

DelcoigneYves commented 3 months ago

Yes, in the app I'm currently working on, there are some deeplinked screens that can be opened in various ways. Simply put:

When popping the last screen, we would like to pop to either the items list if it is currently in the stack, or to the home screen otherwise.

Currently we are resolving this (with auto_route) by checking if the items list screen is in the stack, pop until this screen, and otherwise pop till root.

JaspervanRiet commented 3 months ago

Can you create this by creating items list under a StatefulLocation, and then calling .root() from item action confirm screen? That should give you the same behavior on both.

With DuckRouter I'm trying to be at least a little bit opinionated and avoid supporting unnatural mobile UX. I find that often popUntil does lead to unnatural patterns. If we have to support it, we can. But I'm just trying to find the specific use case of it :)

DelcoigneYves commented 3 months ago

That sounds like a pretty good idea, I’ll try it out tomorrow!

And I do understand the reluctance. I love the simplicity, now you can actually understand what is going on under the hood.

I’m still thinking about opening up the Stack info though. Currently, we have a few async services running in the background, each of which can trigger a redirect to the login screen. We have had some issues in the past when this redirect is triggered from multiple services simultaneously, so we added a check to see if the login screen is in the stack (or last entry in the stack, can’t recall at this time), and only navigate if the login screen is not in the stack yet. What do you think about exposing this info?

JaspervanRiet commented 3 months ago

You could do:

      final router = ... // create/get DuckRouter
      router.routerDelegate.currentConfiguration.locations //do something here

or

      router.configuration.findLocation('login')

And maybe even more ways!

Providing an even easier way to solve this use case feels like it's stepping outside of our bounds as router authors. To me this use case seems like one wherein it's reasonable as package authors to say: this is something for the package user to implement state for. Multiple services all triggering the same navigation seems like something to solve in general. Hope that makes sense.

DelcoigneYves commented 3 months ago

I managed to get the popUntil working with the StatefulLocation, so that scenario is covered for me, thanks!

As for the stack info: I'm an idiot, I didn't realize you could access it like you mentioned 😅 I just tried it, and it works indeed as expected.

I did have some difficulties getting the root method to work, I'll create a separate issue for that.

Thanks for the help!