Solen Dogan
Solen Dogan

Reputation: 149

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

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.

İs this possible in flutter apps?

Upvotes: 5

Views: 3114

Answers (4)

Sajjad
Sajjad

Reputation: 3218

You can use

if (kDebugMode)
  doSomething();

Upvotes: 0

Darkonen
Darkonen

Reputation: 23

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

Upvotes: 0

Harmen
Harmen

Reputation: 992

I would love this functionality too.

I opened an Feature request on Flutter's github: https://github.com/flutter/flutter/issues/105250

Upvotes: 0

Peter Koltai
Peter Koltai

Reputation: 9734

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.

Upvotes: 6

Related Questions