uni_links icon indicating copy to clipboard operation
uni_links copied to clipboard

getUriLinksStream().listen((Uri uri) invoked twice

Open Chepond opened this issue 5 years ago • 9 comments

Describe the bug getUriLinksStream().listen((Uri uri) { }, onError: (err) { }); } on PlatformException { // Handle exception by warning the user their action did not succeed // return? } this method is invoked twice everytime the app is being called by scheme I am using custom deep linking, not associated one..

To Reproduce Steps to reproduce the behavior:

  1. set up custom scheme
  2. calling scheme:// in webpage javascript: windows.location = "scheme://";
  3. code invoked twice

Expected behavior code invoked once should be expected

Smartphone (please complete the following information): iOS iphone XS Max simulator iOS 12

Additional context

my code snipset as below:

Future<Null> initUniLinks() async {

try {
  String initialLink = await getInitialLink();
  getUriLinksStream().listen((Uri uri) {

    Map<String, String> query = uri.queryParameters;
    Map<String, dynamic> json = jsonDecode(query['json']);

    DeepLinkDao deepLinkDao = DeepLinkDao.fromJson(json);
    handleDeepLink(deepLinkDao);
  }, onError: (err) {
    var a = 1;
    var b = a + 1;
  });
} on PlatformException {
  // Handle exception by warning the user their action did not succeed
  // return?
}

}

Chepond avatar Mar 10 '19 05:03 Chepond

same thing on Android

d-silveira avatar Jan 22 '20 19:01 d-silveira

Same here:

I ended up doing something like this with https://pub.dev/packages/synchronized:

    // Attach a listener to catch any links when app is running in the background
    _uniLinksSub = getUriLinksStream().listen((Uri uri) async {
      await _previousUniUriLock.synchronized(() async {
        if (_previousUniUri == uri) // this seems to be invoked twice so ignore the second one
          _previousUniUri = null;   // clear the uri here though so the user can manually invoke twice
        else {
          await processUri(uri);
          _previousUniUri = uri;
        }
      });
    }, onError: (err) {
      print('uri stream error: $err');
    });

djpnewton avatar Dec 03 '20 23:12 djpnewton

Same here on iOS

tamirrab avatar Aug 12 '21 10:08 tamirrab

Same here except it'll fire 4-5 times

linjonathan2001 avatar Aug 29 '21 21:08 linjonathan2001

any idea how resolve this case? same error here

igorfastronicorrea avatar Mar 17 '22 13:03 igorfastronicorrea

I am stuck on this issue. For detail, the uriLinkStream.listen() the onData props returns twice the same URI.

uriLinkStream.listen((Uri? uri) async {
        print('Deep link : $uri'); // I got twice comment here
      });

Anyone has ideas or solutions for this issue!!

vinhhoangdo avatar Aug 11 '22 03:08 vinhhoangdo

Any updates?

ultraon avatar Jul 20 '23 22:07 ultraon

In my case I have an endless number of updates. It seems to depend on urls length and device, becouse i have links which was listen once. In my case phone is Huawei p20 pro.

KonstantenKomkov avatar Dec 20 '23 11:12 KonstantenKomkov