What is the difference between streamController.add() and streamController.sink.add()?

Nothing. This does the same thing internally.

The real purpose of .sink property is to pass it as parameter of other object. Such as :

MyClass(
  sink: myController.sink,
)

This prevents classes to access to properties they shouldn’t be able to.

But StreamController implements Sink so what’s the point ?

Well true. But casting StreamController to Sink is different than creating a Sink.

For example, the class that uses Sink could very well do the following :

StreamSink sink = StreamController();
if (sink is StreamController) { // this is true
    // access StreamController custom methods
}

The sink field is here to prevent this. It translates into the following :

StreamSink sink = StreamController().sink;
if (sink is StreamController) { // false this time
   // never reached
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)