Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Stream<Null> is allowed?

Sometimes, when I´m watching some projects that work with streams, I see something like:

final controller = StreamController<Null>();

and then:

controller.sink.add(null);

So, is allowed to pass null in streams? Why?

like image 495
Little Monkey Avatar asked Oct 18 '25 21:10

Little Monkey


1 Answers

Null as generic type argument was used before void was supported and means in this case that only the occurence of the even is meaningful, but the event value is not.

With Null the value null is the only valid event value. With void a callback function can be passed that does not take any parameter.

like image 78
Günter Zöchbauer Avatar answered Oct 20 '25 11:10

Günter Zöchbauer