简体   繁体   中英

Url Launcher does not work with MissingPluginException Flutter

I am trying to launch a url in my flutter application. What i'm trying to do is very simple and it works in all other projects except for this one! The browser should be launched on an inkwell onTap event. I tried the exact same code in other projects and worked. I also tried to create a new flutter project and the code worked.

The app does not crash and i don't get any error but on Debug i get a missing plugin exception.

I tried flutter clean and flutter run but didn't work! I tried invalidating cache and restart but also didn't work! I tried removing and re installing the plugin but also didn't work!

Here's the code:

_launchMapsUrl() async {
  final url = 'https://www.google.com';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    print('Could not launch $url');
  }
}

the onTap:

    onTap: () {
      _launchMapsUrl();
   },

The Compiled and Target SDK versions are 29 and the version of the launcher in my pubspec.yaml is url_launcher: ^5.7.10

For the record the other projects that the code worked in are of the same versions

I think it has something to do with caching issue i'm not really sure, i'm very new to flutter.

Can you please recommend a solution.

If you are using hot restart or hot reload, it won't do the trick. Since Flutter has to inject plugin dependencies into the platform-specific parts of your app, hot reload/hot restart is not enough to trigger the injection.

Close the app and execute flutter run command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM