Navaron Bracke

add comment for barcode reader cancel on web

... ... @@ -148,7 +148,8 @@ class MobileScannerWeb extends MobileScannerPlatform {
return;
}
_barcodesSubscription?.cancel();
// Ensure the barcode scanner is stopped, by cancelling the subscription.
await _barcodesSubscription?.cancel();
_barcodesSubscription = null;
await _barcodeReader.stop();
... ...
... ... @@ -160,6 +160,9 @@ final class ZXingBarcodeReader extends BarcodeReader {
);
};
// The onCancel() method of the controller is called
// when the stream subscription returned by this method is cancelled in `MobileScannerWeb.stop()`.
// This avoids both leaving the barcode scanner running and a memory leak for the stream subscription.
controller.onCancel = () async {
_reader?.stopContinuousDecode.callAsFunction();
_reader?.reset.callAsFunction();
... ...