I'm debugging a Flutter/Dart app with IntelliJ and I have weird thing happenings: some methods are called but the debugger does not stop at breakpoints.
After having lost hours on that, I finally understood that the problem is caused by the debugger itself: to display values of variables, it calls methods by itself, causing odd behaviors. What can be done to prevent this?
/*
Output in Debug:
current: 1
current: 2
current: 3
current: 1
current: 2
current: 3
breakpoint here
current: 1
current: 2
current: 3
current: 1
current: 2
current: 3
current: 1
for: 1
current: 2
for: 2
current: 3
for: 3
Output in Run:
breakpoint here
current: 1
for: 1
current: 2
for: 2
current: 3
for: 3
*/
main() {
var iterable = TestIterable();
print('breakpoint here');
for (var item in iterable) {
print('for: $item');
}
}
class TestIterable extends IterableBase {
@override
Iterator get iterator => TestIterator();
}
class TestIterator extends Iterator {
int _index = 0;
@override
bool moveNext() => _index++ < 3;
@override
get current {
print('current: $_index');
return _index;
}
}
Not specific to IDEA, I can see the same behavior in Dart Dev Tools : as soon as I try to inspect iterable
variable, the code is run and value printed to console:
Not sure if this is expected, I'd suggest contacting Dart dev team by submitting an issue to https://github.com/dart-lang/sdk/issues
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.