skip to Main Content

I was working on a flutter project and for simplicity’s sake, decided to allow the redirection of users for the "Help & Support" section towards the website. So, I tried to create an asynchronous function to allow that redirection.

So, I tried to use a Future function that uses the launchURL from called launch_url.

Future<void> _launchURL(Uri url) async {
  if (await canLaunchUrl(url)) {
    await launchUrl(url);
  } else {
    throw 'Could not launch $url';
  }
}

However, it always threw this exception:

I/UrlLauncher(30788): component name for https://flutter.dev/ is null
I/UrlLauncher(30788): component name for https://flutter.dev is null
E/flutter (30788): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Could not launch https://flutter.dev/
E/flutter (30788): #0      _launchURL (package:clothing_app/screens/settings.dart:385:5)
E/flutter (30788): <asynchronous suspension>
E/flutter (30788):

Note: When I tried to run on the computer of a friend of mine, it worked without that exception.

On both occasions, we used the Android Studio emulators to see the layouts of the app and VS Code to write our flutter code (connected to the emulator device). I additionally tried to run the code on my physical phone, but the same problem occured.

2

Answers


  1. Chosen as BEST ANSWER

    Thank you, when I used the queries it worked.

    Besides, I added these two lines as well in AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    

  2. You probably did not add the <queries> …</queries> meta data required by url_launcher on AndroidManifest.xml

    Please refer to the documentation here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search