Home > Blockchain >  How to debug Dart code using the Flutter SDK on a terminal?
How to debug Dart code using the Flutter SDK on a terminal?

Time:11-16

void main() {
  var values = List<String>.filled(3, 0);

  values[0] = 'abc';
  values[1] = 'def';
  values[2] = 'ghi';
}

I am trying to have a regular debugging experience with breakpoints on my code. However, I don't want to design a UI screen on my emulator just to run a code that does not require UI presentation.

In other words, I am trying to run dart code in isolation from UI.

CodePudding user response:

using VScode you can open a full new dart project with the ability to debug and test your code with:

1- click on ctrl shift p from your keyboard

2- search for Dart: new project, and click it

3- choose console application

4- choose a location for the dart project

5- that's it, now you can open the project folder from VScode and play in the main.dart with your code, and debug it.

Using other editors, you can do the same just from the terminal running this in the command line:

dart create nameOfProject

CodePudding user response:

if dart --version works.

then you can do dart filename.dart

don't forget to print

CodePudding user response:

The error is that the code is trying to access an element in the list that does not exist. The list only has 3 elements, so trying to access the 4th element (values[3]) will cause an error.

To fix this, you can either remove the line that tries to access values[3], or you can add another element to the list.

  • Related