使用fvm在VSCode中更改Flutter版本,但Flutter版本无法正常工作。

huangapple go评论104阅读模式
英文:

Use fvm to change flutter version in vscode, but the flutter version not work?

问题

I added fvm to my project and set it up like this. Now I can run all the commands, for example, fvm use x.x.x or fvm flutter pub get. Everything works.

BUT when running the application through VSCode directly (Play button or shortcut), it always uses my latest installed SDK version. Why is it not starting with the current flutter version?

This is my 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
}
}

What am I missing here? How do I configure fvm to work correctly with VSCode?

英文:

I added fvm to my project and set it up like this. Now I can run all the commands for example fvm use x.x.x or fvm flutter pub get. Everything works.

BUT when running the application through VSCode directly (Play button or shortcut) it always uses my latest install SDK version. Why is it not starting with the current flutter version ?

This is my 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
    }
  }

What am I missing here? How do I configure fvm to work correctly with VSCode?

答案1

得分: 4

我假设您已经正确设置了.fvm文件夹,即其中包含符号链接flutter_sdk(指向当前选择的SDK)和fvm_config.json

在您的settings.json文件中,您还需要设置SDK本身的位置:

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

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

英文:

I'm assuming you have the .fvm folder set up properly? ie. It contains the symlink flutter_sdk (which points to the currently selected SDK) and the fvm_config.json.

In your settings.json file, you also need to set the location of the SDK itself:

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

Which will point to the same symlink.

答案2

得分: -1

以下是代码部分的翻译:

For exists project
such as change version from 3.7.10 to 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 将被更新,符号链接 .fvm/flutter_sdk 也将更新到版本 3.7.12。

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

变为

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

.vscode/settings.json

{
  "dart.flutterSdkPath": ".fvm/flutter_sdk",
  // 从搜索中删除 .fvm 文件
  "search.exclude": {
    "**/.fvm": true
  },
  // 从文件监视中删除
  "files.watcherExclude": {
    "**/.fvm": true
  }
}

切换到你的项目并使用 fvm use 3.7.12 -f 来更改版本。

For new project
To prevent compatibility issues with new version, may be create new project is best choice.

$ 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"],
    // 从搜索中删除 .fvm 文件
    "search.exclude": {
        "**/.fvm": true
    },
    // 从文件监视中删除
    "files.watcherExclude": {
        "**/.fvm": true
    }
}
  1. 更改当前的 Flutter SDK
    打开 VSCode 命令面板,快捷键是

Ctrl + Shift + p(Windows)

Cmd + Shift + p(macOS)

输入命令 Flutter: Change SDK 并选择该命令,这将列出你已安装的所有 SDK 版本,选择你想要的版本。

这将更新文件 .vscode/settings.json

{
    "dart.flutterSdkPaths": ["/Users/xxx/fvm/versions"],
    "dart.flutterSdkPath": "/Users/xxx/fvm/versions/3.7.12", // 这是你选择的新版本
    // 从搜索中删除 .fvm 文件
    "search.exclude": {
        "**/.fvm": true
    },
    // 从文件监视中删除
    "files.watcherExclude": {
        "**/.fvm": true
    }
}

不要忘记如果你使用这种方法,移除 .fvm 文件夹:

$ rm -rf .fvm
英文:

General Apporch is below

For exists project
such as change version from 3.7.10 to 3.7.12

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

with command fvm use 3.7.12 -f, the file .fvm/fvm_config.json will update and the sybolink .fvm/flutter_sdk also was updated to version 3.7.12.

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

to

{
  "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 to you project and use fvm use 3.7.12 -f to change version.

For new project
To prevent compatibility issues with new version, may be create new project is best choice.

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

the command fvm use 3.7.12 -f will create .fvm/flutter_sdk and .fvm/fvm_config.json file.

add .vscode/settings.json to your project

Please read more detail with official website fvm

The following answers are only for the above questions

You can list all installed local sdk versions first. such as:

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

3.10.0
3.7.12
  1. edit below user xxx to your's
{
    "dart.flutterSdkPaths": ["/Users/xxx/fvm/versions"],
    // Remove .fvm files from search
    "search.exclude": {
        "**/.fvm": true
    },
    // Remove from file watching
    "files.watcherExclude": {
        "**/.fvm": true
    }
}
  1. Change Current Flutter SDK
    open vscode command palette, the shortcuts is

Ctrl + Shift + p for windows

Cmd + Shift + p for macOS

input command Flutter: Change SDK and select the command, this will be list all you have install sdks, select the one you wanted.

this will update the file .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
    }
}

don't forget remove the folder .fvm, if you use this apporch.

$ rm -rf .fvm

huangapple
  • 本文由 发表于 2023年2月14日 06:56:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定