Google News
logo
Flutter - Interview Questions
What is Stream in Flutter?
A stream is a sequence of asynchronous events. It provides an asynchronous sequence of data. It is the same as a pipe where we put some value on the one end, and if we have a listener on the other end, it will receive that value. We can keep multiple listeners in a stream, and all of those will receive the same value when put in the pipeline.

We can process a stream by using the await for or listen() from the Stream API. It has a way to respond to errors. We can create streams in many ways, but they can be used in the same way.

Example : 
Future<int> sumStream(Stream<int> stream) async {  
    var sum = 0;  
    await for (var value in stream) {  
      sum = sum + value;  
    }  
    return sum;  
  }
Advertisement