I’m trying to open a URL but I get this Error, when I run an android app on the emulator or in a device the result on the screen is that nothing happens but I get "Unhandled Exception: MissingPluginException", but when I use windows app works fine.
launchUrl support: android, windows, ios
E/flutter ( 6260): [ERROR: flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method launch on channel plugins.flutter.io/url_launcher_android)
E/flutter ( 6260): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294:7)
E/flutter ( 6260):
E/flutter ( 6260): #1 _launchURL (package:peliculas/screens/details_cast.dart:371:8)
E/flutter ( 6260):
My code:
Future<void> _launchURL(String url) async {
final Uri uri = Uri(scheme: "https", host: url);
if (!await launchUrl(uri)) {
throw 'Could not launch $url';
}
-I’m using url ="www.google.com"
-emulator api 30
What I tried before:
- flutter clean
- flutter pug get
- flutter run
- uninstall app
- flutter doctor -v is OK
- I'm not using hot restart or hot reload
UPDATE:
It happen in other projects but now is just in this one, I have another project where I use only this method and after updating closing and opening again starts to work but the main project didn’t work. I move the project to another place and open but I get the same.
SOLUTION:
To solve this problem, in my case that url_launcher didn’t work in my project but when I create a new one it works fine, just follow what "FirstComment" says, create a new project copy the lib folder to the new one, and set Manifest and pubspec configuration like the old project, also move other files like asset.
3
Answers
run these commands in terminal
1 :
flutter clean
2 :
flutter pub get
and Restart your app
UPDATED
You are using the url_launcher package which uses native device methods in order to work properly as also shown in the error
Add the below code in AndroidManifest.xml above the
<application>
elementAdd the below code in Info.plist inside of
<dict>
elementNow, in the lib folder create a file launch_url.dart and paste the below code
Kindly uninstall the old app on your phone and run the below commands
After this run the app again and click on the button as shown below to open the url in the browser.
add this to your android manifest