Is there a way to change value while debugging a Flutter App

Viewed 670

As in all languages Debugging is a core concept as we all need to do it:) I am trying to edit and set a value while running a Flutter App in debug Mode. However i could not find any place where i can edit the value and set it to test the effect of the change in the flow.

  • In VS Code i have put breakpoints and run the app in the debug mode. Set watchpoints etc.. but could not find a way to edit a value?

İs this possible in flutter apps?

4 Answers

I don't think this is possible. In Visual Studio Code there would be a Set Value command on the context menu if you clicked on any variable which you can change, but it is not available when debugging a Flutter application. Even if you go to Debug Console when paused on a breakpoint, and assign a new value to a variable there, it is not reflected when you resume running your code.

I found a way to be able to change variable values on debug mode in a tricky way.

The idea is to execute a method that changes de value from the debugger.

String variableToChange = 'test';
final changeVariableValue = (String value) => variableToChange = value;
final debbugPointer = null;

In order to make it your you should add the debugger marker in the third line. Then on the debuuger screen once stoped execute:

changeValue('your new value);

You will see varible has changed on VSCode debuger.

Executing command

Result

You can use

if (kDebugMode)
  doSomething();
Related