juliuscanute / qr_code_scanner

QR Code Scanner for Flutter
BSD 2-Clause "Simplified" License
1.02k stars 813 forks source link

[BUG] [iOS] stutter in pageview #201

Open cahix opened 3 years ago

cahix commented 3 years ago

On iOS there is a strong stuttering when switching from the qr-scanner to another widget in a PageView. Switching to the qr-scanner is fine.

Flutter (Channel beta, 1.25.0-8.1.pre, on Microsoft Windows [Version 10.0.18363.1256], locale en-US

smofe commented 3 years ago

Have you tried running your project in --release or --profile mode? I've had performance issues on android that were only present when running the app in debug mode.

cahix commented 3 years ago

@smofe yes i did. it seems like the closing of the camera causes the stutter on my iphone

cahix commented 3 years ago

fixed by calling "controller.pauseCamera()" before disposing

cahix commented 3 years ago

issue is back on versions above 0.1.0

juliansteenbakker commented 3 years ago

With version 0.3.2 disposing is done differently. Can you please try again?

cahix commented 3 years ago

i still have the same problem

cahix commented 3 years ago

also, i can see the camera preview in the background of my other widgets in the page-view just before the scanner disposes.

cahix commented 3 years ago

@juliansteenbakker any chance you have a look at this again? I am still using version 0.1.0 because it does not cause stuttering when the qr-scanner is disposed in the background.

This is my dispose method to make it work:

  @override
  void dispose() {
    if (_qrController != null) {
      if (Platform.isIOS) _qrController.pauseCamera();
      _qrController.dispose();
    }
    super.dispose();
  }

Best regards

seth35us commented 3 years ago

``@cahix I tried your fix, but got the following error after switching tabs multiple times:

MTBBarcodeScanner.m:973 "Scan rect cannot be set when not (yet) scanning. You may want to set it within didStartScanningBlock."

I have the scanner set in a bottomNavigationBar. I think this is related to bug #283.

Is it possible that the code below is causing the crash? We need to ensure that scanning has started before setting the dimensions.

          `case "setDimensions":
                let arguments = call.arguments as! Dictionary<String, Double>
                self?.setDimensions(result,
                                    width: arguments["width"] ?? 0,
                                    height: arguments["height"] ?? 0,
                                    scanArea: arguments["scanArea"] ?? 0,
                                    scanAreaOffset: arguments["scanAreaOffset"] ?? 0)
            case "startScan":
                self?.startScan(call.arguments as! Array<Int>, result)`
juliansteenbakker commented 3 years ago

Sorry for the late response but i haven't had the time to look at this. As a matter of fact, i'm almost ready to publish the first release with MLKit support. In my tests this works like so much better than the current frameworks used. So i'd advise you to try that out when i'm releasing it.

Is it possible that the code below is causing the crash? We need to ensure that scanning has started before setting the dimensions.

I do think that would cause an issue. I have stumbled on multiple errors regarding 'NSInternalInconsistencyException', reason: 'Scan rect cannot be set when not (yet) scanning. You may want to set it within didStartScanningBlock.' Ill try to add a check to see if it's scanning before setting the rect.

cahix commented 3 years ago

Will you be releasing it as a version in this package or will it be a completely new one? Just making sure I do not miss it.

juliansteenbakker commented 3 years ago

Will you be releasing it as a version in this package or will it be a completely new one? Just making sure I do not miss it.

I just released the first alpha version. It's integrated in this package. Keep in mind the class names can change until it reaches beta.