Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Future values while debugging in dart?

Please upvote: https://github.com/dart-lang/sdk/issues/40198

I am wondering how I can get access to the value of a future, while debugging in vs-code? Right now i need to introduce another temp variable to get the debugger to await the statement. This is how I am accessing a value at the moment:

 Future<void> disconnect2() async {
    var conn = await isConnected;
    if (conn) await internalDisconnect();
  }

But I would like to write the following:

  Future<void> disconnect() async {
    if (await isConnected) await internalDisconnect();
  }

And still be able to access the value of isConnected with the debugger.

What I tried so far:

Try to add the expression (await isConnected) to the watch. enter image description here Tried to evaluate the expression (await isConnected) in the debug console. enter image description here Try to add the expression isConnected to the watch. enter image description here Tried to evaluate the expression isConnected in the debug console. enter image description here Tried to access the value through hovering over the instance. In the screenshot it is null, but most of the time I get to access only the future object. enter image description here

Is there any easy way to access the value of a future while debugging?

like image 502
Niklas Raab Avatar asked May 03 '26 08:05

Niklas Raab


1 Answers

You cannot see the value of future value while it is not awaited and loaded. The reason for it, future type is waiting the data, so it reserve part of memory for future value. You can access it only after getting the value f.e. value from REST API. You can use then method and see the value there.

someFuture(arg).then((erg) => print(erg));
like image 74
Islomkhuja Akhrarov Avatar answered May 06 '26 02:05

Islomkhuja Akhrarov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!