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
220 stars 81 forks source link

Potential Issue with Link Handling in Flutter Beta Causing Duplicate Triggers in app_links Plugin #152

Closed naivetoby closed 2 months ago

naivetoby commented 2 months ago

Description

I've encountered a potential issue while running a project demo using the app_links plugin on an iPhone simulator. The problem seems to be related to how Flutter Beta handles link events, leading to duplicate triggers.

Steps to Reproduce

  1. Modify the code to add logging:

    onGenerateRoute: (RouteSettings settings) {
        Widget routeWidget = defaultScreen();
    
        // Mimic web routing
        final routeName = settings.name;
    
        // Add Log
        debugPrint('routeName: $routeName');
    
        if (routeName != null) {
          if (routeName.startsWith('/book/')) {
            // Navigated to /book/:id
            routeWidget = customScreen(
              routeName.substring(routeName.indexOf('/book/')),
            );
          } else if (routeName == '/book') {
            // Navigated to /book without other parameters
            routeWidget = customScreen("None");
          }
        }
    
        return MaterialPageRoute(
          builder: (context) => routeWidget,
          settings: settings,
          fullscreenDialog: true,
        );
    }
  2. Run the following command:

    xcrun simctl openurl booted "app://www.example.com/#/book/hello-world"

Expected Behavior

Actual Behavior

It appears that Flutter Beta may have changed the way it listens to links, resulting in the route being triggered multiple times. This issue was observed on both iOS (simulator) and Android devices.

Environment

Additional Information

I am unsure if this is the appropriate place to report this issue, but I have noticed similar behavior on Android as well. Any guidance or fixes would be appreciated.

llfbandit commented 2 months ago

Thanks for the feedback. To be sure, you didn't change anything in the example project? According to your log, it feels like Flutter deep linking is enabled. The example calls the route with fragment only (/book/hello-world) while the last entry shows full path (/#/book/hello-world, just a guess).

This package only provides a bridge to retrieve URIs from native side. While navigation may be a target for apps, what is done with the URI is out of the scope of this package.

naivetoby commented 2 months ago

Thank you for your prompt reply.

To clarify, I didn't make any changes to the example project other than adding a single line of logging code:

debugPrint('routeName: $routeName');

Additionally, I updated Flutter to the latest Beta version. The issue I observed occurred right after the upgrade, with no other modifications to the codebase.

Given that this package primarily bridges URIs from the native side, I understand that navigation handling is outside its scope. However, the observed behavior seems to be linked to the way Flutter Beta is processing deep links, possibly due to changes in how it handles fragments in URIs.

You might want to try updating to the latest Flutter Beta and see if you can replicate the issue on your end. It could help determine if there's an unintended interaction between Flutter Beta and how the package retrieves URIs.

Thanks again for your assistance.

llfbandit commented 2 months ago

I'll pay attention to check this for next Flutter release. Anyway from the log, the link is handled only once from the package (Flutter shouldn't be involved here). So I'm pretty confident.

I'm leaving this issue opened as a note.

naivetoby commented 2 months ago

i got it, thanks

https://github.com/llfbandit/app_links/commit/9649162700f55f9265e95256528cd3f07387a13a