How to fix this kind of errors when using then
?
void handleSubmitWrapper() {
final future = handleSubmit();
future.then(context.loaderOverlay.hide()); // error
}
Future<void> handleSubmit() async {
...
}
This expression has a type of ‘void’ so its value can’t be used. Try
checking to see if you’re using the correct API; there might be a
function or call that returns void you didn’t expect. Also check type
parameters and variables which might also be void.dart
2
Answers
You must provide an anonymous function in your case, which has type FutureOr Function(void).
Since you tagged this
dart:async
, lets have a look at what you could do when you don’t use thatthen
anachronism:Bonus: you are now able to
await
this method. Or continue it with athen
if you must. Or not. Your choice.