0

I have the following stream subscription

Stream<Uint8List> stream = await USBSerialSingleton.instance.inputStream;
usbStream = stream.listen(onDataReceivedFromUSBSerial);

The inputStream is a broadcast stream exposed like this.

Future<Stream<Uint8List>> get inputStream async {
final UsbPort port = await this.port;
return port.inputStream.asBroadcastStream();
}

I would like to stop listening to the stream, so I am calling

usbStream.cancel();

But I keep receiving messages on my onDataReceivedFromUSBSerial method. I keep getting messages on the onDataReceivedFromUSBSerial even if I close the dialogue that all this is implemented on.

Question: How do I stop listening to my usbStream?

4

1 回答 1

2

您必须等待订阅取消,所以这样做:

await usbStream.cancel();
于 2020-06-17T03:41:54.483 回答