illegal_ async_ generator_ return_ type
Functions
marked 'async*'
must
have
a
return
type
that
is
a
supertype
of 'Stream
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 either
Stream
or a supertype of
Stream
.
Example
#
The following code produces this diagnostic because the body of the
function
f
has the 'async*' modifier even though the return type
int
isn't a supertype of
Stream
:
int f() async* {}
Common fixes
#
If the function should be asynchronous, then change the return type to be
either
Stream
or a supertype of
Stream
:
Stream<int> f() async* {}
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.9.2. Page last updated on 2025-9-4. View source or report an issue.