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
Thank you, when I used the queries it worked.
Besides, I added these two lines as well in AndroidManifest.xml:
You probably did not add the
<queries> …</queries>
meta data required by url_launcher on AndroidManifest.xmlPlease refer to the documentation here