Skip to content

Instantly share code, notes, and snippets.

@vital-edu
Created May 17, 2023 19:55
Show Gist options
  • Save vital-edu/be8ffb6e839c507e7da81eef795f5d20 to your computer and use it in GitHub Desktop.
Save vital-edu/be8ffb6e839c507e7da81eef795f5d20 to your computer and use it in GitHub Desktop.
Dart 3: Breakpoint Issue
void main() {
var data = {
'number': 20,
'canProcess': true,
};
final worker = Worker(data);
print(worker.result);
final result = worker.maybeProcess(data, (data) {
if (data case {'number': final number}) {
// Breakpoint 2: without issue
return number % 2 == 0;
}
return null;
});
print(result);
print(worker.getResult());
print(dataHasEventNumber(data));
}
class Worker {
final dynamic _data;
Worker(this._data);
bool? get result {
return maybeProcess(_data, (data) {
if (data case {'number': final number}) {
// Breakpoint 1: with issue
return number % 2 == 0;
}
return null;
});
}
bool? getResult() {
return maybeProcess(_data, (data) {
if (data case {'number': final number}) {
// Breakpoint 3: with issue
return number % 2 == 0;
}
return null;
});
}
bool? maybeProcess<String>(dynamic data, bool? Function(dynamic) fun) {
if (data case {'canProcess': final value} when value == true) {
return fun(data);
}
return null;
}
}
bool? dataHasEventNumber(data) {
if (data case {'number': final number}) {
// Breakpoint 4: without issue
return number % 2 == 0;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment