yield_in_non_generator
yield ステートメントはジェネレーター関数('async*' または 'sync*' でマークされたもの)内にある必要があります。
yield* ステートメントはジェネレーター関数('async*' または 'sync*' でマークされたもの)内にある必要があります。
説明
#yield または yield* ステートメントが、async* または sync* 修飾子でマークされていない関数本体に現れた場合に、アナライザーはこの診断を生成します。
例
#以下のコードは、関数本体に修飾子がない関数で yield が使用されているため、この診断を生成します。
dart
Iterable<int> get digits {
yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
}以下のコードは、関数本体に async* 修飾子ではなく async 修飾子がある関数で yield* が使用されているため、この診断を生成します。
dart
Stream<int> get digits async {
yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
}一般的な修正
#修飾子を追加するか、既存の修飾子を async* または sync* に変更してください。
dart
Iterable<int> get digits sync* {
yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
}