illegal_async_return_type
Functions marked 'async' must have a return type which is a supertype of 'Future'.
Description
#The analyzer produces this diagnostic when the body of a function has the async
modifier even though the return type of the function isn't assignable to Future
.
Example
#The following code produces this diagnostic because the body of the function f
has the async
modifier even though the return type isn't assignable to Future
:
int f() async {
return 0;
}
Common fixes
#If the function should be asynchronous, then change the return type to be assignable to Future
:
Future<int> f() async {
return 0;
}
If the function should be synchronous, then remove the async
modifier:
int f() => 0;
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.