6

I'm attempting to use Flutter's url_launcher plugin to open webpages.

When I click a button url_launcher opens a webpage successfully. However, if I then navigate back by swiping left, or using the soft back button, the app crashes. The logs say

java.lang.RuntimeException: Unable to destroy activity {uk.co.pottertour.map_edinburgh_guide_airbnb/io.flutter.plugins.urllauncher.WebViewActivity}: java.lang.IllegalArgumentException: Receiver not registered: io.flutter.plugins.urllauncher.WebViewActivity$1@8152196

It says WebViewActivity so presumably Url_Launcher isn't opening an external browser but an in-app Webview.

This is pretty critical, this app is basically a hub for exciting things.

I was suspicious that my didChangeAppLifecycleState function was causing the error since it occurred on resume, but no, it's when Flutter runs build & rebuilds the screen.

I've tried commenting out parts of my build process that included url_launcher links, believing the rebuild triggered it, but this does not help. Perhaps there is some background asynchronous process, that throws this error before the app is painted to the screen. To do with url_launcher.

Sam
  • 1,659
  • 4
  • 23
  • 42

4 Answers4

6

I had your same problem and I suggest you this solution if you don't want an in-app handling with url_launcher (https://pub.dev/packages/url_launcher#browser-vs-in-app-handling):

Future<void> _launchUrl(Uri url) async {
  if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
    throw Exception('Could not launch $url');
  }
}

Using mode: LaunchMode.externalApplication the link will open outside your app and you shouldn't have any problems when you navigate back into your app.

  • 1
    Yes cheers Matteo, worked for me too. I'll give it a little longer to see if another solution is offered, but I think the inAppWebview mode is probably broken at present, or at least when it's triggered by ```mode: LaunchMode.platformDefault``` – Sam May 15 '23 at 08:41
  • This worked for me, thank you! Hope it gets fixed soon in the package – SilkeNL May 17 '23 at 08:34
3

This is fixed in url_launched_android 6.0.34. The issue was tracked in https://github.com/flutter/flutter/issues/127014

Tomasz Noinski
  • 456
  • 2
  • 10
2

For now, you can override dependency with

dependency_overrides:
  url_launcher_android: "<=6.0.32"
Tushar Anchliya
  • 387
  • 1
  • 3
  • 7
  • 1
    This worked for me thank you! But this is just a temporary solution until they fix the issue. – Fran May 17 '23 at 15:49
1

This is fixed in url_launched_android Version No. 6.0.34.

To upgrade the transitive dependency use this command in the terminal:

flutter pub upgrade url_launcher_android

Refrence: https://github.com/flutter/flutter/issues/127014

SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96