llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
214 stars 78 forks source link

Overlapping Subscriptions on appLinks.uriLinkStream Across Multiple Screens #165

Open Splagov opened 1 week ago

Splagov commented 1 week ago

Describe the bug

I’m facing a problem when trying to subscribe to appLinks.uriLinkStream on multiple screens in a Flutter app. The use case requires handling deep links on both the initial screen and another subsequent screen. The flow looks like this:

  1. On the initial screen, I subscribe to uriLinkStream to parse and handle a deep link.
  2. After parsing and handling on the first screen, I navigate to the second screen, where I also subscribe to uriLinkStream to handle the same link but in a different way.
  3. However, while the deep link handler on the first screen works, the handler on the second screen does not trigger, even though I am using a similar subscription setup.

Key Observations:

Code Example: _subscription = appLinks.uriLinkStream.listen((uri) { deepLinkHandler.handleDeepLink(uri); });

Use Case: I need to handle the deep link differently on two screens: On the initial screen, I process the deep link and extract some metadata. On the second screen, after fetching additional data from the network, I want to handle the same deep link again but in a different way. It seems like the uriLinkStream is not designed to handle multiple subscriptions across different screens, especially when navigation is involved. However, multiple subscriptions in a single screen work as expected.

Any suggestions on how to properly manage deep link subscriptions across multiple screens would be helpful!

Does it related to

[ ] App Links (Android)
[ ] Deep Links (Android)
[ ] Universal Links (iOS)
[ ] or Custom URL schemes? (iOS)
[X] Custom URL schemes? (iOS and Android)

Does the example project work?

[X ] Yes
[ ] No
[ ] Irrelevant here

Did you fully read the instructions for the targeted platform before submitting this issue? yes

Uploaded your files to webserver, HTTPS, direct connection, scheme pattern setup, ...

[ ] Yes
[ ] No
[X ] Irrelevant here

Splagov commented 1 week ago

is it bcz second listener subscribed after event occurred? In order to trigger both listeners, they must be subscribed on the moment of the event?