robben
robben

Reputation: 785

Unable to debug flutter dart code in VS Code, Unverified Breakpoint error

files structureWhen the code is not running, I can add breakpoint (round red circle), but as soon as it goes into debug mode, it turns into unverified breakpoint (grey hollow circle) and doesn't work at all. However, the same project works well on other systems. I've no idea what the problem is or what the solution would be. I've tried reinstalling flutter SDK numerous times, and have gone through a lot of links on SOF and GitHub regarding this, but none has been helpful enough.

Environment - VS Code, Flutter version: 1.17.2

Flutter doctor -

[✓] Flutter (Channel stable, v1.17.2, on Mac OS X 10.15.3 19D76, locale en-GB)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[!] Android Studio (not installed)
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

My launch.json File -

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter: Run all Tests",
            "type": "dart",
            "request": "launch",
            "program": "./test/"
        },
        {
            "name": "Dart: Run all Tests",
            "type": "dart",
            "request": "launch",
            "program": "./test/"
        },
        {
            "name": "Dart",
            "type": "dart",
            "request": "launch",
            "program": "bin/main.dart"
        },
    {
        "name": "Dart: Attach to Process",
        "type": "dart",
        "request": "attach"
    },
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart"
        }
    ]
}

Also, If you know any good alternatives to VSCode and Android Studio for Flutter, please share.

Upvotes: 17

Views: 29017

Answers (16)

Csaba Mihaly
Csaba Mihaly

Reputation: 329

I use vscode, most of the time I connect to my linux pc from my windows laptop with the remote extension through ssh.

First I noticed this problem with the remote session, then I noticed it happened on the vscode installed on the linux pc too. I have removed all the folders I could find in my home directory related to vscode, flutter and vscode-server. That fixed it there with linux vscode app.

But the remote session still didn't work. Then I did the same thing on my laptop, removed every config directory related to vscode and flutter. I think the culprit here is vscode. It has a few config related directories. If I remember correctly one "." folder in the user directory and one somewhere in AppData. After that I reconfigured vscode(sync, extensions) and that solved it.

TLDR: remove vs code config/cache folders

Upvotes: 0

Mateusz Pietras
Mateusz Pietras

Reputation: 109

For others facing this error on Linux My setup: Kubuntu 23.10, Flutter 3.16.0, VSC 1.84.2

The issue most commonly has grounds in VSC installation path. If you installed VSC by snap - it most likely will not work.

  1. Check if you have code installed by snap snap list - look for code (if you have many apps installed you can try snap list | grep code)
  2. If present, remove code from snap snap remove code
  3. Remove all VSC cache rm -r ~/.config/Code
  4. Log out & log in
  5. Install VSC by sudo apt install code
  6. If the issue occurs only on web then check if chrome is installed by snap and also remove it & install by sudo apt install google-chrome-stable

Hope it helps, it took me 4h to find any working solution.

Upvotes: 1

Mohammad Fasha
Mohammad Fasha

Reputation: 478

Try to rebuild your launch.json file. Remove the old file from the .vscode directory in vscode, then goto Run and Debug window and create a new launch file.

Upvotes: 1

pmg7670
pmg7670

Reputation: 141

I had a similar problem. My platform is Ubuntu 20.04. I was setting the breakpoint in vscode expecting the vscode debugger to work immediately, but no. After an hour of googling, I hit the Flutter docs on the DevTools page.

To resolve :

  1. Open your flutter project in vscode.
  2. Follow the 'Install from VS Code' section of the docs to install DevTools.
  3. Start your emulator, wait for it to completely load up.
  4. Select Run => Start Debugging.
  5. Check that app is running as expected in the emulator.
  6. Select commandPalette => Dart:Open DevTools => 'Open DevTools in web browser'. The DevTools dashboard opens in a new browser tab.
  7. Select the Debugger tab.
  8. Open the relevent code file and add your breakpoint by clicking the leftmost breakpoint column at the required line.
  9. Progress your app by clicking the emulator UI. Vscode debugger should stop at your breakpoint.
  10. Use the vscode debugging controls thereafter.

Upvotes: 0

user1932098
user1932098

Reputation: 21

In my case, the parents folder contains special character (#):

.../#Projects/my_project/

Remove the # and the debug goes well:

.../Projects/my_project/

Upvotes: 2

Damien
Damien

Reputation: 1218

I had a similar problem. I solved by completely uninstalling and reinstalling Vscode + remove the data. See here

Upvotes: 1

Bin4ry
Bin4ry

Reputation: 732

For flutter-web I had to change back to <base href="/"> within the web/index.html. A custom href lead to a none-debuggable project.

Upvotes: 2

kohjakob
kohjakob

Reputation: 788

For anybody running into this problem while trying to debug external libraries or sdk code: Make sure you checked "Dart: Debug External Libraries" and "Dart: Debug Sdk Libraries" under Settings > Extensions > Dart & Flutter as described here.

enter image description here

You can also add the following to your settings.json

"dart.debugExternalLibraries": true,
"dart.debugSdkLibraries": true,

Upvotes: 10

Samuel Surya
Samuel Surya

Reputation: 455

I faced the same problem with debug in certain dart files, but the other files I could.

Then I realized that it happened when I call another file and this trick would help:

Instead of typing:

import '../form/productdetail.dart';

I replaced with:

import 'package:myapp/form/productdetail.dart';

and it helped.

Upvotes: -1

Rodrigo porras
Rodrigo porras

Reputation: 236

i came from mac and always use fn + f5, on windows that means start withouth debugggin, that was my mistake.

Upvotes: 11

Kavya Shravan
Kavya Shravan

Reputation: 363

Have faced the same issue, resolved by stopping the current active session and click on RUN and select START DEBUGGING. This worked for me.

Upvotes: 0

Zujaj Misbah Khan
Zujaj Misbah Khan

Reputation: 819

enter image description here

Navigate to the Run Tab and select Dart & Flutter from the drop down menu, finally hit the play button.

Upvotes: 5

boris_dv
boris_dv

Reputation: 143

 "version": "0.2.0",
  "configurations": [
    {
      "name": "Flutter",
      "request": "launch",
      "type": "dart",
      "flutterMode": "debug"
    }
  ]
}

This is my launch.json file ... changing "flutterMode" from profile to debug solved the issue ... if you dont have this line adding it could help.

Upvotes: 10

Edmond
Edmond

Reputation: 91

Clicking Run on the top menu in VS code and selecting 'Enable all breakpoints' worked for me. Though you have to place your breakpoint first.

You can also try placing your breakpoint and save your code, then leave the emulator running and close and restart your vs code IDE and run the app with debugging.

Upvotes: 6

ishon19
ishon19

Reputation: 347

I was also facing the same issue, I am looking for the exact reason but removing the launch.json file worked for me.

Upvotes: 0

Tolga Kartal
Tolga Kartal

Reputation: 633

Your main.dart file's path is not specified right. so in this block

    "name": "Dart",
    "type": "dart",
    "request": "launch",
    "program": "bin/main.dart"

please use

"program": "lib/main.dart"

Upvotes: 0

Related Questions