dart 在vscode中使用fvm改变flutter版本,但是flutter版本不工作?

iyfamqjs  于 12个月前  发布在  Vscode
关注(0)|答案(2)|浏览(202)

我将fvm添加到我的项目中,并将其设置为this。现在我可以运行所有命令,例如fvm use x.x.xfvm flutter pub get。一切正常
但是当直接通过VSCode(播放按钮或快捷方式)运行应用程序时,它总是使用我最新安装的SDK版本。为什么不是从 * 当前的flutter版本 * 开始?
这是我的settings.json

{
  "dart.flutterSdkPaths": [
    "/Users/usr/fvm/versions"
  ],
    // Remove .fvm files from search
    "search.exclude": {
      "**/.fvm": true
    },
    // Remove from file watching
    "files.watcherExclude": {
      "**/.fvm": true
    }
  }

我错过了什么?如何配置fvm,使其与VSCode正常工作?

hjqgdpho

hjqgdpho1#

我假设你已经正确设置了.fvm文件夹?即,它包含符号链接flutter_sdk(指向当前选择的SDK)和fvm_config.json
在您的settings.json文件中,您还需要设置SDK本身的位置:

"dart.flutterSdkPath": ".fvm/flutter_sdk",

这将指向相同的符号链接。

mpgws1up

mpgws1up2#

阿朴里将军在下面
对于现有项目,例如将版本从3.7.10更改为3.7.12

$ fvm install 3.7.12
$ cd project
$ fvm use 3.7.12 -f

使用命令fvm use 3.7.12 -f,文件.fvm/fvm_config.json将更新,并且sybolink .fvm/flutter_sdk也被更新到版本3.7.12。

{
  "flutterSdkVersion": "3.7.10",
  "flavors": {}
}

{
  "flutterSdkVersion": "3.7.12",
  "flavors": {}
}

.vscode/settings.json

{
  "dart.flutterSdkPath": ".fvm/flutter_sdk",
  // Remove .fvm files from search
  "search.exclude": {
    "**/.fvm": true
  },
  // Remove from file watching
  "files.watcherExclude": {
    "**/.fvm": true
  }
}

cd到您的项目,并使用fvm use 3.7.12 -f更改版本。
对于新项目为了防止与新版本的兼容性问题,可能创建新项目是最好的选择。

$ cd project
$ fvm use 3.7.12 -f
$ fvm flutter create --platforms=android --org com.xxx .

命令fvm use 3.7.12 -f将创建.fvm/flutter_sdk.fvm/fvm_config.json文件。
.vscode/settings.json添加到项目
更多详情请浏览fvm官方网站
以下回答仅针对上述问题
您可以先列出所有已安装的本地sdk版本。例如:

$ fvm list
Cache Directory:  /Users/xxx/fvm/versions

3.10.0
3.7.12

1.编辑下面的用户xxx到您的

{
    "dart.flutterSdkPaths": ["/Users/xxx/fvm/versions"],
    // Remove .fvm files from search
    "search.exclude": {
        "**/.fvm": true
    },
    // Remove from file watching
    "files.watcherExclude": {
        "**/.fvm": true
    }
}

1.更改当前Flutter SDK打开vscode命令面板,快捷键为
Ctrl + Shift + p用于Windows
Cmd + Shift + p for macOS
输入命令Flutter: Change SDK并选择该命令,这将列出所有你已经安装的sdk,选择你想要的。
这将更新文件.vscode/settings.json

{
    "dart.flutterSdkPaths": ["/Users/xxx/fvm/versions"],
    "dart.flutterSdkPath": "/Users/xxx/fvm/versions/3.7.12", // this is your select new version
    // Remove .fvm files from search
    "search.exclude": {
        "**/.fvm": true
    },
    // Remove from file watching
    "files.watcherExclude": {
        "**/.fvm": true
    }
}

不要忘记删除文件夹.fvm,如果你使用这个approch。

$ rm -rf .fvm

相关问题