avoid-passing-async-when-sync-expected
preset: recommended
Avoid passing asynchronous function as an argument where a synchronous function is expected.
note
For this rule it's recommended to exclude the test
folder.
Example
❌ Bad:
void doSomethingWithCallback(VoidCallback function) {
...
function();
...
}
void main() {
// LINT
doSomethingWithCallback(() async {
await Future.delayed(Duration(seconds: 1));
print('Hello World');
});
}
✅ Good:
void doSomethingWithCallback(VoidCallback function) {
...
function();
...
}
void main() {
doSomethingWithCallback(() {
print('Hello World');
});
}