Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if StreamSubscription is canceled

To put it simple:

How do i check if a StreamSubscription is canceled?

There is no

_myCustomSub.isCanceled
like image 609
Marc Ma Avatar asked Oct 16 '22 09:10

Marc Ma


2 Answers

It seems you'd have to use one of two methods:

  1. onDone method - and retain in a seperate variable whether the stream was closed, or..
  2. cancel method - and await the future that signals that the StreamSubscription was canceled.

Don't know of any other way.

like image 140
wildeyes Avatar answered Oct 18 '22 23:10

wildeyes


I've run into a similar situation and my solution was to make my StreamSubscription nullable and set it to null after cancel().

await _newAlertsStreamSubscription?.cancel().then((_) {
     _newAlertsStreamSubscription = null;
});
like image 41
Pip Avatar answered Oct 19 '22 01:10

Pip