flutterdartvisual-studio-codevscode-debugger

Is it possible to specify the Flutter SDK path for the VSCODE extension?


I am having the setup that my flutter-sdk lives inside the projects root because I am using a version management system (FVM). When I run my programs from the console I run 'fvm flutter run' from the console but I also want to be able to start a debugging session with that SDK in the projects root ... therefore my question is if it is possible to specify the SDK path for launching a Flutter App in debug mode and if how would i do it?


Solution

  • In vscode press ctrl+shift+p, search for 'set flutter sdk', and you can identify your Flutter installations and dart as well. You can edit this manually also in the settings.json.

    You can try this, and create a launch.json, by going to Run in VScode menu, then Add Configurations,

    add the following, mind you, your project's directories.

    {
        "configurations": [
            {
                "program": "lib/main.dart",
                "name": "YOUR APP NAME",
                "cwd": "/home/u/Projects/fireflutter/live-projects/YOUR_PROJECT_FOLDER/",
                "type": "dart",
                "request": "launch",
                "flutterMode": "debug",
                "args": [
                    // "--web-port",
                    // "8080",
                    // "--no-sound-null-safety",
                    // pass your arguments here, whatever you would type 
                    //in the terminal when you would use i.e 
                    //flutter run --no-sound-null-safety[I love null safety by the way, 
                    //but this is a common problem for people who still want to opt out of it.
                ],
            }
        ],
        "dart.flutterSdkPath": "/home/u/Downloads/sdks/flutter",
        "dart.sdkPath": "/home/u/Downloads/sdks/flutter/bin/dart",
    }
    

    If you get an error saying Error: spawn /bin/sh ENOENT, it means that your path is incorrect, and you have to fix either your program or cwd or name. Please update on the result of this.