For this recipe, we'll add a second listener to the stream that we have built in the previous recipes in this chapter:
- At the top of the _StreamHomePageState class, in the main.dart file, declare a second StreamSubscription, called subscription2, and a string, called values:
StreamSubscription subscription2;
String values = '';
- In the initState method, edit the first subscription and listen to the stream with the second subscription:
subscription = stream.listen((event) {
setState(() {
values += event.toString() + ' - ';
});
});
subscription2 = stream.listen((event) {
setState(() {
values += event.toString() + ' - ';
});
});
- Run the app. You should see an error as shown in the following screenshot:
- Still in the initState method, set the stream as a broadcast stream:
void initState() {
numberStream = NumberStream();
numberStreamController = numberStream...