Solved: What does 'yield' keyword do in flutter?

Question

Asked by Newaj on April 20, 2019 (source).

What does the yield keyword actually do in Dart?

Answer

Question answered by Jacob P (source).

yield adds a value to the output stream of the surrounding async* function. It's like return, but doesn't terminate the function.

See https://dart.dev/guides/language/language-tour#generators

Stream asynchronousNaturalsTo(n) async* {
  int k = 0;
  while (k < n) yield k++;
}

When the yield statement executes, it adds the result of evaluating its expression to the stream. It doesn’t necessarily suspend (though in the current implementations it does).

DART FLUTTER YIELD
SHARE: