We use Flutter with VSCode. We have been able to debug as expected with the following commands.

fvm flutter run --debug --flavor production --target lib/main-production.dart

But when we press F5 to run from VSCode, the following code throws a MissingPluginException.

~/fvm/versions/2.10.5/packages/flutter/lib/src/services/platform_channel.dart

  @optionalTypeArgs
  Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async {
    assert(method != null);
    final ByteData? result = await binaryMessenger.send(
      name,
      codec.encodeMethodCall(MethodCall(method, arguments)),
    );
    if (result == null) {
      if (missingOk) {
        return null;
      }
      throw MissingPluginException('No implementation found for method $method on channel $name');
    }
    return codec.decodeEnvelope(result) as T?;
  }

We want to debug pressing F5 as well as the command case. We have set up launch.json as follows Isn't this the same command we are running?

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Production(Debug)",
      "request": "launch",
      "type": "dart",
      "program": "lib/main-production.dart",
      "args": [
        "--debug",
        "--flavor",
        "production",
      ]
    },
  ]
}

We are using fvm, but it looks like Flutter 2.10.5 is being used both in VSCode and in the command.

.fvm/fvm_config.json

{
  "flutterSdkVersion": "2.10.5",
  "flavors": {}
}
fvm --version
2.4.1
fvm flutter --version
Flutter 2.10.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 5464c5bac7 (5 months ago) • 2022-04-18 09:55:37 -0700
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2

[Added] We also set the global Flutter version to 2.10.5 but the error remained the same.

% fvm use 2.10.5      
Project now uses Flutter [2.10.5]

% fvm global 2.10.5
Flutter "2.10.5" has been set as global

% fvm doctor

FVM Version: 2.4.1
___________________________________________________

FVM config found:
___________________________________________________

Project: daigas_capture
Directory: /Users/xxxxx/zzzzz
Version: 2.10.5
Project Flavor: None selected
___________________________________________________

Version is currently cached locally.

Cache Path: /Users/xxxxx/fvm/versions/2.10.5
Channel: false
SDK Version: 2.10.5

IDE Links
VSCode: .fvm/flutter_sdk
Android Studio: /Users/xxxxx/zzzzz/.fvm/flutter_sdk

Configured env paths:
___________________________________________________

Flutter:
/Users/xxxxx/fvm/default/bin/flutter

Dart:
/usr/local/bin/dart

FVM_HOME:
not set


Solution 1: Arin Faraj

Make sure to follow the fvm configuration for VSCode Which states that you need these settings inside .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
  }
}