1

My understanding is that

  • a Future is used to represent a potential value, or error, that will be available at some time in the future. Receivers of a Future can register callbacks that handle the value or error once it is available.
  • Streams are part of Dart, and Flutter “inherits” them. There are two types of streams in Flutter: single subscription streams and broadcast streams. Single subscription streams are the default. They work well when you're only using a particular stream on one screen.

What are the similarities and differences between them?

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44
  • 1
    Does this answer your question? [Flutter StreamBuilder vs FutureBuilder](https://stackoverflow.com/questions/50844519/flutter-streambuilder-vs-futurebuilder) – Pathik Patel Jun 09 '22 at 12:07
  • No, my question is regarding Stream vs Future not, StreamBuilder vs FutureBuilder – Shirsh Shukla Jun 10 '22 at 09:10

2 Answers2

4

Both futures and streams are parts of Dart. The main similarity between them is that they are both used for asynchronous programming. The main difference between them is:

  • a future is used for a value which may be not available right now, may become available at some later moment, and then will not change. We want to react when the value becomes available (and e.g. display it)
  • a stream is used when some value changes over time and we want to react to the changes (e.g. by displaying the current value)
Wojtek Surowka
  • 20,535
  • 4
  • 44
  • 51
1

One of the similarities is that both will return in the future(asynchronous). One difference is that Future only returns once. The stream will return again and again.