【问题标题】:插件项目:location_web 未找到。请更新 settings.gradle。我该如何解决?
【发布时间】:2020-10-02 12:33:53
【问题描述】:

我在我的 android Flutter 应用程序中使用 google maps api 和 location pub,dev 包,并尝试使用 api 中的 url 显示图像。 这是带有一些代码的网址:

class LocationHelper{
  static String mapviewpointer({double latitude, double longitude}){
    return "https://maps.googleapis.com/maps/api/staticmap?center=$latitude,$longitude&zoom=13&size=600x300&maptype=roadmap&markers=color:pink%7Clabel:C%7C$latitude,$longitude&key=$GOOGLE_API_KEY";
  }
}

它抛出了以下错误消息:

Plugin project :location_web not found. Please update settings.gradle;

我不确定如何解决此错误。

这是我在终端中收到的另一个错误:

I/flutter (21880): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future%3CString%3E'

我收到上述错误消息的区域在我的代码中:

Future <String> _getUserLocation() async{
  final locData = await Location().getLocation();
  final staticMapUrl = LocationHelper.mapviewpointer(
    latitude: locData.latitude, 
    longitude: locData.longitude,
    );
    return staticMapUrl;
}

final mapview = _getUserLocation();


class NearbyScreen extends StatelessWidget {
  @override
  //LocationHelper.mapviewpointer(latitude: )
  
  Widget build(BuildContext context) {
    return  Column(
            children: <Widget>[
              Container(height:170, width: double.infinity,
              child:Image.network(mapview.toString())
              ),
              Text("hello"),
            ],
          );
  }
}

这是否与我在 _getUserlocation 函数中返回 Future&lt;String&gt; 而不仅仅是 string 的事实有关?我该如何解决这个问题?

【问题讨论】:

  • 你能出示你的pubspec.yaml吗?

标签: flutter dart google-maps-api-3 flutter-dependencies flutter-web


【解决方案1】:

为安装了 facebook 翻转器的用户修复

我会将此添加为评论,但让我将其发布为具有正确代码格式的答案。

如果你安装了 facebook 的 Flipper,并带有相关的 flutter_flipperkit 插件,那么你的 settings.gradle 应该已经被修改了。

要使用@Peter Haddad 和@Paulo Belo 建议的修复方法,您需要保持 Flipper 的插件加载并添加其他条件:

plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    if (name == 'flutter_flipperkit') {
        // flipper loading
        include ':flipper-no-op'
        project(':flipper-no-op').projectDir = new File(pluginDirectory, 'flipper-no-op')
    }
    else {
        // location_web not found fix
        include ":$name"
        project(":$name").projectDir = pluginDirectory
    }
}

希望这对某人有所帮助。

【讨论】:

    【解决方案2】:

    删除 ProjectName/Build 文件夹,它为我解决了问题。

    【讨论】:

      【解决方案3】:

      在你的 Flutter 应用中添加 -> android -> settings.gradle

      def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
      
      def plugins = new Properties()
      def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
      if (pluginsFile.exists()) {
          pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
      }
      
      plugins.each { name, path ->
          def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
          include ":$name"
          project(":$name").projectDir = pluginDirectory
      }
      

      如所见here

      有关该问题的更多信息here

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,按照@Peter Haddad 的回答,我复制并替换了 settings.gradle 中的代码(全部),我在解析属性和文件的符号时遇到了错误。

        修复它:转到工具 -> Flutter -> 在 Android Studio 中打开以进行编辑

        在 Android Studio 窗口中转到 File -> Invalidate Cache and Restart

        这似乎为我解决了问题。

        【讨论】:

        • 无需打开Android Studio清理缓存,在终端中使用:flutter clean
        • 在 AndroidStudio 4.1 中,您可以从工具菜单中执行 fflutter/clean
        【解决方案5】:

        使用以下settings.gradle

        include ':app'
        
        def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
        
        def plugins = new Properties()
        def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
        if (pluginsFile.exists()) {
            pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
        }
        
        plugins.each { name, path ->
            def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
            include ":$name"
            project(":$name").projectDir = pluginDirectory
        }
        

        这将创建一个.flutter-plugin 文件,其中包含插件及其路径。

        【讨论】:

        • 非常感谢!但是,在尝试显示地图图像时,我仍然收到此错误消息:“I/flutter (10600): The following ArgumentError was throwed resolve an image codec: I/flutter (10600): Invalid argument(s): No host specified in URI file:///Instance%20of%20'Future%3CString%3E'" 会有什么问题?
        • 代码的哪一行出现此错误?或者做了什么之后?
        • getUserLocation() 返回一个Future&lt;String&gt;Image.network 需要一个网址。因此最好的办法是使用FutureBuilder 并在其中调用Image.network 图像
        • 为什么会出现这个错误?这个脚本有什么作用?
        • 顺便说一句,我检查了我的 .flutter-plugins 文件,该文件是由最近的 Flutter 版本创建的,它包含 location_web 路径。可能正如@PeterHaddad 所说,一些插件不支持新的设置定义
        猜你喜欢
        • 2021-02-09
        • 2020-09-06
        • 2020-10-11
        • 2021-06-01
        • 2022-10-21
        • 2020-10-14
        • 2021-02-16
        • 2021-04-09
        • 1970-01-01
        相关资源
        最近更新 更多