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

Deep links for linux not working #84

Closed liquidiert closed 6 months ago

liquidiert commented 7 months ago

Describe the bug

Tested deep linking with the current main branch and am getting following error:

flutter: `app_links` threw an error: 'package:flutter/src/services/platform_channel.dart': Failed assertion: line 542 pos 7: '_binaryMessenger != null || BindingBase.debugBindingType() != null':
Cannot set the method call handler before the binary messenger has been initialized. This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding has been initialized.
You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() before this or by passing a custom BinaryMessenger instance to MethodChannel().. The app may not function as expected until you remove this plugin from pubspec.yaml

I am using WidgetsFlutterBinding.ensureInitialized() in my main function so this is rather a bug in the package itself. Also the the example project throws another error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method getInitialAppLink on channel com.llfbandit.app_links/messages)
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:320:7)
<asynchronous suspension>
#1      AppLinksMethodChannel.getInitialAppLinkString (package:app_links/src/app_links_method_channel.dart:29:18)
<asynchronous suspension>
#2      AppLinksMethodChannel.getInitialAppLink (package:app_links/src/app_links_method_channel.dart:23:20)
<asynchronous suspension>
#3      _MyAppState.initDeepLinks (package:app_links_example/main.dart:71:21)
<asynchronous suspension>

Is it related to

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

Does the example project work?

[ ] Yes
[x] 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, ...

[x] Yes
[ ] No
[ ] Irrelevant here

bdlukaa commented 6 months ago

I also am experiencing this issue! From the example app:

Building Linux application...                                           
flutter: `app_links` threw an error: 'package:flutter/src/services/platform_channel.dart': Failed assertion: line 554 pos 7: '_binaryMessenger != null || BindingBase.debugBindingType() != null': Cannot set the method call handler before the binary messenger has been initialized. This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding has been initialized. You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() before this or by passing a custom BinaryMessenger instance to MethodChannel().. The app may not function as expected until you remove this plugin from pubspec.yaml

I debugged this issue and the problem is that dartPluginClass is being used to register the linux platform, but it uses methods from the gtk package, which calls a platform method. At the stage the app_links linux plugin is registered, the platform binding hasn't been initialized yet and gtk fails to connect to the linux platform (This is the reason why MissingPluginException is being thrown - flutter fails to register the dart class and fall backs to the method_channel implementation).

llfbandit commented 6 months ago

@bdlukaa Thanks for the feedback, I think I get it. I released beta 3 as a fix attempt. Tell me if this is better (I don't have linux).

bdlukaa commented 6 months ago

Thank you for your efforts. The issue seems to be fixed now!

llfbandit commented 6 months ago

Released in v3.5.0

amehroz-mufin commented 4 months ago

Hey @bdlukaa Can You Please Guide Me Through How You Got Deeplinks Configured in Linux as i am having a Hard Time Tried Everything. Even the Example Package But Nothing Works For Me Can You Please Share Your Insights of What I might be Doing Wrong Here.

bdlukaa commented 4 months ago

@mehroz-mufin This issue was tracking the app initialization issue when app_links was added as a dependency. I also can not use deep links in the Linux platform, but didn't have the time to look what is wrong.

liquidiert commented 4 months ago

@mehroz-mufin whta did you try so far? Did you set up a desktop file with the %u parameter?