Streams #2

Now that you know how to create Streams in Dart, we will dive into retrieving and processing events from the Stream.

Retrieving Events From Stream

In this lesson, you will learn to retrieve and print the events/numbers for the stream(s) created in the last lesson. You will learn two approaches to this.

Using listen

In this example, you will print events of a Stream using listen by adding the subscription to the given Stream.

A Stream is created and consists of numbers from 1 to 5. It’s retrieved by listening to the Stream using the listen() method. Let’s print some messages before starting the stream and after the stream is finished.

Get hands-on with 1200+ tech skills courses.