You can think of a stream as a one-way pipe, with two ends. One end of the pipe only allows you to insert data, and the other end is where data gets out.
In Flutter, you can do the following:
- You can use a stream controller to control a stream.
- A stream controller has a sink property to insert new data.
- The stream property of StreamController is a way out of StreamController.
You can see a diagram of this concept in the following diagram:
In the app you have built in this recipe, the first step involved the creation of a stream controller, and you did that in the NumberStream class, with the help of the following command:
StreamController<int> controller = StreamController<int>();
As you can see, a stream controller is generic, and you can choose its type (in this case, int) depending on the needs of your app.
The next step was adding data to the stream controller, leveraging its sink property, and we did that with the following...