skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. For now, you can override dependency with

    dependency_overrides:
      url_launcher_android: "<=6.0.32"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search