avioli / uni_links

Flutter plugin for accepting incoming links.
BSD 2-Clause "Simplified" License
563 stars 303 forks source link

How to clear initialLink after redirect to another page? #54

Closed sandhysanjaya1206 closed 4 years ago

sandhysanjaya1206 commented 4 years ago

How to clear initialLink after redirect to another page?

because after redirect to another page and open previous page, initialLink still have data so redirect to another page again

d-silveira commented 4 years ago

this is a real issue, please someone check this. We need to clear the initialLink after reading it!

avioli commented 4 years ago

As it says in the README under Usage about the Initial Link:

Returns the link that the app was started with, if any.

I should add that getInitialLink (or getInitialUri) may only return a non-null value if the app was cold started and not resumed from the background.

So... your app was cold started...

Your user may start your app via the icon on their home screen. In this case the app will not have been started via an external link, so calling getInitialLink will return null.

On the other hand - your users may start your app via a link from another app, like a browser. In that case calling getInitialLink will return that specific link - something like com.my-domain.my-app-scheme://whatever?key1=param1&key2=param2 or https://my-fancy-app-domain.com.au/path/to/whatever/?auth_key=uuid&user_id=uuid.

This link is not meant and will not change throughout your app's life, until it is terminated - either by the system or by the user, force quitting it. It should not be cleared or reset. You should listen to changes via getLinksStream or getUriLinksStream, which notifies its listeners when a new link arrives. The listeners are notified when the app is resumed from the background, meaning the app is no longer terminated, but "minimised", while other apps are in the foreground and switch to your already running app.

I've written in the README a bit more about app start from a link.

This is how the two platforms are made. I'm open for discussion if I'm wrong and either of the two platforms - Android or iOS - support multiple entry points to a cold started app. The plugin is trying to give Flutter developers access to these details in the most convenient way. In some cases your best approach is to implement your own native solution (using Swift, Objective-C, Kotlin or Java), that is tailored specifically to your app's needs.

I hope this makes sense?

Feel free to re-open if needed.

Edit: added more clarifications.