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

It can't catch killed app #60

Closed mkbsugita closed 9 months ago

mkbsugita commented 1 year ago

Describe the bug

If the app wake up, it can work. But I killed the app it can't work.

    final appLinks = AppLinks();
    // Subscribe to all events when app is started.
    // (Use allStringLinkStream to get it as [String])
    appLinks.allUriLinkStream.listen((uri) {
      // Do something (navigation, ...)
      onUrlSchemeUpdate(context, url: uri);
    });

  void onUrlSchemeUpdate(BuildContext context, {required Uri url}) {
    // bla bla ...
  }

Does it related to

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

Does the example project work?

[o ] Yes
[ ] No
[ ] Irrelevant here

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

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

[ ] Yes
[o ] No
[ ] Irrelevant here

BhargavJani commented 1 year ago

are you find the solution?

mkbsugita commented 1 year ago

@BhargavJani Did you meet same bug?

I guess I should get url from the code of Decomposed usage in README.

final uri = await _appLinks.getLatestAppLink();
llfbandit commented 9 months ago

If you launch the plugin before your flutter app you need this: WidgetsFlutterBinding.ensureInitialized();

This method will allow to access native code before inflating the app view tree.

If it's not the case or already having this, could you attach a simple android reproducer?

DennisKragekjaer commented 9 months ago

Same issue here on Android

RichardRaue commented 9 months ago

First, thank you for this lib. I appreciate your work. However, we face the same issue as mentioned above: when a user opens the app with a deeplink and the app is created from scratch, getInitialAppLink() returns 'null' and the deep linking fails. It works well when app is in background.

The behaviour is the same on Android and iOS.

Here's the code:

main.dart

Future<void> main([List<String>? param]) async {
  WidgetsFlutterBinding.ensureInitialized();
  await firebaseInitializer.initFirebase();
  ...
  runApp(MyApp());
}

main_screen.dart (1st widget)

class MainScreen extends ConsumerStatefulWidget {

  @override
    Widget build(BuildContext context, WidgetRef ref) {
    initDeepLinkListeners(context, ref);
    ...
  }

  Future<void> initDeepLinkListeners(BuildContext context, WidgetRef ref) async {
    final _appLinks = AppLinks();
    Uri? initialDeepLink = await _appLinks.getInitialAppLink(); // this is 'null' when app is created fresh; otherwise it works!
    ...
  }
}

Is this setup correct?

llfbandit commented 9 months ago

I guess not.

For resolving purpose, move AppLinks() intanciation to main function to see if the very first link is now catched. You can leave the code as it is in your example. While AppLinks() is not singleton the underlying platform will act as one. I will enforce this in later version.

vinothvino42 commented 9 months ago

I'm also facing the same issue. It's working fine in foreground or background state but not in the terminated state.

llfbandit commented 9 months ago

Can you just read the comment above yours?

I need to instanciate the plugin early to register it to the engine. After this, in your flutter app, use it normally.