简单点说:
如何检查StreamSubscription是否已取消?
没有
_myCustomSub.isCanceled
答案 0 :(得分:0)
答案 1 :(得分:0)
我认为这可能是您想要的:
final streamController = StreamController();
streamController.onCancel = (){};
要收到订阅通知,请在您指定onListen参数时 创建StreamController。当onListen回调在 流第一个订阅者。如果您指定onCancel回调, 当控制器失去最后一个订阅者时调用。
由以下方法定义的onListen,onPause,onResume和onCancel回调 当流的侦听器时,流将调用StreamController 状态更改
此外,这可能会有所帮助:
//Whether there is a subscriber on the [Stream]
streamController.hasListener
答案 2 :(得分:0)
是的,正如其他人所说,没有办法检查流订阅是否被取消,这有点蹩脚。我猜您无权访问 StreamController
,所以这是我的两个选项。
将 _myCustomSub
设置为 null
作为取消订阅的标志并采取相应措施。
另一种方法是将 bool
值 (isSubCanceled
) 与 _myCustomSub
变量放在一起,并使用它代替 _myCustomSub.isCanceled
。>