illegal_ sync_ generator_ return_ type
Details about the 'illegal_sync_generator_return_type' diagnostic produced by the Dart analyzer.
Functions marked 'sync*' must have a return type that is a
supertype of 'Iterable
Description
#
The analyzer produces this diagnostic when the body of a
function has the
sync* modifier even though the return type of the
function isn't either Iterable or a supertype of
Iterable.
Example
#
The following code produces this diagnostic because the body
of the function f has the 'sync*' modifier even
though the return type int
isn't a supertype of Iterable:
int f() sync* {}
Common fixes
#
If the function should return an iterable, then change the
return type to be either Iterable or a supertype
of Iterable:
Iterable<int> f() sync* {}
If the function should return a single value, then remove the
sync*
modifier:
int f() => 0;
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.