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
756 stars 446 forks source link

Multiple scanning black screen #380

Closed 549064368 closed 1 year ago

549064368 commented 1 year ago

Thread Performance Checker: -[AVCaptureSession startRunning] should be called from background thread. Calling it on the main thread can lead to UI unresponsiveness PID: 4055, TID: 1413886 Backtrace

3 Runner 0x0000000101d992d8 $s14mobile_scanner24SwiftMobileScannerPluginC5startyySo17FlutterMethodCallC_yypSgctF + 6368 4 Runner 0x0000000101d95f80 $s14mobile_scanner24SwiftMobileScannerPluginC6handle_6resultySo17FlutterMethodCallC_yypSgctF + 688 5 Runner 0x0000000101d96330 $s14mobile_scanner24SwiftMobileScannerPluginC6handle_6resultySo17FlutterMethodCallC_yypSgctFTo + 124 6 Flutter 0x0000000106bbd56c __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 112 7 Flutter 0x0000000106695b2c _ZN7flutter25PlatformMessageHandlerIos21HandlePlatformMessageENSt3110unique_ptrINS_15PlatformMessageENS1_14default_deleteIS3_EEEE_block_invoke + 116 8 libdispatch.dylib 0x00000001041d808c _dispatch_call_block_and_release + 24 9 libdispatch.dylib 0x00000001041d98c4 _dispatch_client_callout + 16 10 libdispatch.dylib 0x00000001041e8428 _dispatch_main_queue_drain + 920 11 libdispatch.dylib 0x00000001041e8080 _dispatch_main_queue_callback_4CF + 40 12 CoreFoundation 0x00000001cf129848 A68FCE15-6C1A-38C6-9ED3-7063272D237E + 604232 13 CoreFoundation 0x00000001cf10d4d4 A68FCE15-6C1A-38C6-9ED3-7063272D237E + 488660 14 CoreFoundation 0x00000001cf111b7c CFRunLoopRunSpecific + 584 15 GraphicsServices 0x00000002094a1984 GSEventRunModal + 160 16 UIKitCore 0x00000001d63833c8 AA0A89BD-E48F-31DB-AD5C-5C724CE77D12 + 3625928 17 UIKitCore 0x00000001d6383040 UIApplicationMain + 312 18 Runner 0x0000000100e46d98 main + 64 19 dyld 0x00000001f0b30df0 A2AA3A68-07F7-3D52-A49E-D29D136813F3 + 81392 2022-11-24 13:26:18.260433+0800 Runner[4055:1414263] flutter: MobileScanner: Called start() while already started!

EArminjon commented 1 year ago

Multiple scanning black screen what do you mean ?

Multiple scan screen at the same times ?

549064368 commented 1 year ago

https://user-images.githubusercontent.com/37061607/204760468-4a0f4d43-c5d4-4680-bd26-301e79edc964.mp4

There are two situations

  1. After several consecutive scans, it will not be recognized

  2. After several consecutive scans, the screen will be black

See s for details

EArminjon commented 1 year ago

For the second point, i've fixed it on my app but it's not sexy. The package didn't handle well stop / start. When the package dispose the camera it will stop it. It could took some time... If a new scanner must appear and the previous one is not yet stopped -> black screen. On my app i've a scanner which in a situation can open a second open so i got a black screen. I've create a singleton system to fix that but.... Yep, it's a pain...

549064368 commented 1 year ago

Has the first problem been solved

549064368 commented 1 year ago

对于第二点,我已经在我的应用程序上修复了它,但它并不性感。该包没有很好地处理停止/启动。 当包裹处理相机时,它会停止它。这可能需要一些时间...如果必须出现新的扫描仪并且之前的扫描仪尚未停止 -> 黑屏。在我的应用程序上,我有一个扫描仪,在某种情况下可以打开第二个打开,所以我得到了一个黑屏。我已经创建了一个单例系统来解决这个问题但是......是的,这很痛苦......

When to update

549064368 commented 1 year ago

If I close the interface, can I manually stop it? In this way, there should be no black screen

EArminjon commented 1 year ago

Yep, call dispose on widget dispose method, stop the scanner when you push a new route for example. But you will see console warning / error about double dispose / double stop because of logic error and static inside this package...

549064368 commented 1 year ago

Yep, call dispose on widget dispose method, stop the scanner when you push a new route for example. But you will see console warning / error about double dispose / double stop because of logic error and static inside this package...

Has the first problem been solved

EArminjon commented 1 year ago

Yep, call dispose on widget dispose method, stop the scanner when you push a new route for example. But you will see console warning / error about double dispose / double stop because of logic error and static inside this package...

Has the first problem been solved

Is this a question ? If yes, I didn't know.

549064368 commented 1 year ago

After several consecutive scans, it will not be recognized

549064368 commented 1 year ago

https://user-images.githubusercontent.com/37061607/204978128-143718db-d63c-463f-ae38-3d21f7b002d5.mp4

How to deal with the problem that automatic recognition is not available

EArminjon commented 1 year ago

Scan data BarcodeCapture are sent to this controller :

final StreamController<BarcodeCapture> _barcodesController =
      StreamController.broadcast();
class BarcodeCapture {
  final List<Barcode> barcodes;

  final Uint8List? image;

  BarcodeCapture({
    required this.barcodes,
    this.image,
  });
}

Can you tried to listen directly the controller to check if he got something ?

void initState() {
 controller.barcodes.listen((barcode) {
            print(barcode);
          });
}

Maybe, instance is kept between two screen and the scan is done before your code is ready something weird like that. (i'm not the maintainer)

549064368 commented 1 year ago

add dispose method,There will still be a black screen

juliansteenbakker commented 1 year ago

This is now fixed in v3.0.0. You can use the startDelay parameter in order to prevent a black screen.