What is the difference between Future, Stream, and async/await?

 

TypeDescriptionExample
FutureSingle value returned in futureFuture<int> getData()
StreamSequence of values over timeStream<int> getNumbers()
async/awaitUsed to handle Futures easilyawait getData()

Example:

Stream<int> counter() async* { for (int i = 0; i < 5; i++) { await Future.delayed(Duration(seconds: 1)); yield i; } }

Comments

Popular posts from this blog

1. What is Flutter?

What is FutureBuilder and StreamBuilder?