0

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.

Lalo92
  • 11
  • 4

3 Answers3

1

run these commands in terminal

1 : flutter clean

2 : flutter pub get

and Restart your app

MANISH DAYMA
  • 1,126
  • 3
  • 18
0

UPDATED

You are using the url_launcher package which uses native device methods in order to work properly as also shown in the error

No implementation found for method launch on channel

Add the below code in AndroidManifest.xml above the <application> element

<queries>
<!-- If your app opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
<!-- If your app opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
    </intent>        
</queries>

Add the below code in Info.plist inside of <dict> element

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>https</string>
    <string>http</string>
</array>

Now, in the lib folder create a file launch_url.dart and paste the below code

      import 'package:flutter/material.dart';
      import 'package:url_launcher/url_launcher.dart';

      class LaunchUrl extends StatelessWidget {
      const LaunchUrl({super.key});

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Launch Url'),
          ),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Center(
                child: ElevatedButton(
                  onPressed:  () async => await _launchUrl('https://google.com/'),
                  child: const Text('Launch Url'),
                ),
              ),
            ],
          ),
        );
      }

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

Kindly uninstall the old app on your phone and run the below commands

flutter clean

flutter pub get

After this run the app again and click on the button as shown below to open the url in the browser.

<img src="https://i.stack.imgur.com/6nl3d.gif" alt="launch url in flutter">
  • Hi, I tried it in the order you said, but I am not getting any changes, I get the same error. – Lalo92 Dec 12 '22 at 17:40
  • Check again, the answer is updated. – AmmarJavedOfficial Dec 13 '22 at 11:12
  • Hi!, I tried, but unfortunately, I'm getting the same error, if I open a new project and use this code it works, I don't know if I can change my project or any folder to create a new project with my original code. – Lalo92 Dec 13 '22 at 21:24
  • If the above code is working correctly in your new project then might be something else also wrong in your code. – AmmarJavedOfficial Dec 14 '22 at 05:29
  • To quickly overcome this problem create the new flutter project and copy the lib folder from the old project and replace it with the lib folder in the new project. Copy and paste your assets folder from the old to a new project. Add dependencies in your pubspec.yaml file and do the same configuration in your AndroidManifest.xml, build.gradle and Info.plist files in your new project if you make changes in your old project in these files. – AmmarJavedOfficial Dec 14 '22 at 05:37
  • Hi!, great news!, It works finally, I was trying to move my project to another folder it didn't work but creating a new project and moving lib and the other files worked, in my case, I change the name of my project. Thanks! – Lalo92 Dec 15 '22 at 06:26
  • Good, update the status of the answer. It'll help others. – AmmarJavedOfficial Dec 15 '22 at 06:40
0

add this to your android manifest

<queries>
        <!-- If your app opens https URLs -->
        <intent>
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.BROWSABLE" />
           <data android:scheme="https" />
        </intent>
       
</queries>