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
176 stars 68 forks source link

I just need the next passed URL and no historic URLs #59

Closed rekire closed 1 year ago

rekire commented 1 year ago

I'm using your plugin for a login flow where I redirect the user back to my app. So when I open the browser I start listening for URL like this

openBowser();
final uri = await AppLinks().allUriLinkStream.first;
print('Got $uri');

The problem is that when I call this code twice, that I get directly the result of the first call. I already asked some Flutter developers and it seems that you need to provide this functionality.

I tested this on MacOS, but I think that should be also on Windows.

llfbandit commented 1 year ago

This is because you just keep connecting to the same stream again.

AppLinks should be instanciated only once for all the app instance.

slaci commented 1 year ago

This code gives some more context than you posted on discord. From this I would say you are misusing that stream. You always create a new stream and get the first element of it. The readme of this package recommends using .listen() on the stream (once) and yeah that would be the proper way. Like start listening in a StatefulWidget's initState() and react on the changes you get in its callback. With this stream you get realtime updates. If you need the first or last app link at some point, then maybe the getInitialAppLink() or getLatestAppLink() methods may be more useful.