juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
744 stars 444 forks source link

Provide a way to pause / resume the barcode scanner while leaving the camera preview open #1006

Open navaronbracke opened 1 month ago

navaronbracke commented 1 month ago

A user requested a way to be able to stop the scanner, while the camera preview is still open and providing video input.

This issue serves as a feature request for that.

When resuming the subscription, the old barcode results should be cleared.

burekas7 commented 1 month ago

Hi, @navaronbracke Thanks. My current implementation is like that (using the streamSubscription)

Option1 is using the cancel function Option2 is using the resume, pause function

Option2 is better since we can use the isPause property.

I think it would be nice if the same behavior we be built in.

  void startListenToScannerCapture() {
    streamSubscriptionScanner = controller.barcodes.listen(scannerlistener);
  }

  void scannerlistener(BarcodeCapture barcodeCapture) async {
    Some actions
    .
    .
    .
    .
    //option1:
    await streamSubscription.cancel();

    //option2:
    // setState(() {
    //   streamSubscriptionScanner.pause();
    // });
  }

  // And when button pressed
    onPressed: () {
      //option1:
      startListenToScannerCapture();

      //option2:
      // setState(() {
      //   streamSubscriptionScanner.resume();
      // });
    },
burekas7 commented 1 month ago

@navaronbracke

Note:

By the way, regarding option 2 - There is something weird regarding the StreamSubscription<BarcodeCapture>,

streamSubscriptionScanner = controller.barcodes.listen(scannerlistenerCallback);

When I call: streamSubscription.pause() And move the scanner on a barcode, it doesn't read it, which is ok.

But when I call streamSubscription.resume(), the stream listener callback is called with the scanned value of the barcode that was scanned while I was on pause.

version: 5.0.0-beta.2

burekas7 commented 3 days ago

@navaronbracke

Hi, Any update on the issue here?

Thanks.

navaronbracke commented 3 days ago

No, not yet. Although there is an open PR, but that is to pause the camera preview, not the barcode scanner.

burekas7 commented 3 days ago

No, not yet. Although there is an open PR, but that is to pause the camera preview, not the barcode scanner.

Ok thanks. But when you are going to work on it, pay attention to my additional comment: https://github.com/juliansteenbakker/mobile_scanner/issues/1006#issuecomment-2049613983

navaronbracke commented 2 days ago

We should clear the scanned barcodes in the scanner itself when resuming. We only do that for the start method currently.