What is Difference Between Sink and Stream In Flutter?
StreamSink is a StreamConsumer, which means it can take several streams and processes the events these streams emit.
If it is the StreamSink of a StreamController then all events from the added streams are emitted by the stream created by the StreamController. So in this article, we will go through the difference Between Sink and Stream in Flutter
What is the difference between Sink and Stream In Flutter?
Sink and Stream both are parts of the StreamController. Moreover you can add data to the StreamController using Sink which can be listened via the Stream.
Code Snippet will look like the below:
final _user = StreamController<User>(); Sink get updateUser => _user.sink; Stream<User> get user => _user.stream;
Usage:
updateUser.add(yourUserObject); /
Whenever we add data to the stream via sink it will be emitted. After that it can be listened to using the listen method.
user.listen((user) => print(user));
You can perform various actions before the stream is emitted. Transform method is an example that can be used to transform the input data before it gets emitted.
- Stream – Stream conveyor belt is called as a stream.
- StreamController – StreamController is what controls the stream
- StreamTransformer – StreamTransformer is what processes the input data.
- StreamBuilder – StreamBuilder is a method that takes a stream as an input and provides us with a builder that rebuilds every time there is a new value of a stream.
- Sink – Sink is the property that takes an input
- Stream – Stream is the property that gives the output out of the Stream
Conclusion:
In this article, We have learned about what is the difference between Sink and Stream in Flutter?
Thanks for Reading !!!
So, Kindly drop us your feedback to serve you better.
Do let us know if you need any assistance with Flutter Development?
Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.