How to use Dart streams
In this recipe’s demo, you will change the background color of a screen each second. You will create a list of five colors, and every second you will change the background color of a Container
widget that fills the whole screen.
The color information will be emitted from a Stream
of data. The main screen will need to listen to the Stream
to get the current Color
, and update the background accordingly.
While changing a color isn’t exactly something that strictly requires a Stream
, the principles explained here may apply to more complex scenarios, including getting flows of data from a web service. For instance, you could write a chat app that updates the content based on what users write in real time, or an app that shows stock prices in real time.
Getting ready
In order to follow along with this recipe, you can download the starting code for the project at https://github.com/PacktPublishing/Flutter-Cookbook-Second-Edition/tree...