Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera is not working #1078

Closed
kcs-ravindrapatil opened this issue May 27, 2024 · 6 comments · Fixed by #1086
Closed

Camera is not working #1078

kcs-ravindrapatil opened this issue May 27, 2024 · 6 comments · Fixed by #1086

Comments

@kcs-ravindrapatil
Copy link

Hello folks I have facing some issue while opening scanner, when I opening scanner then it will display info icon instead of camera.

image

camera is not detect properly and not scanning, am providing some code

Declaration/Functions/Methods:

  @override
  void dispose() {
    cameraController.stop();
    cameraController.dispose();
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    startCamera();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.inactive || state == AppLifecycleState.paused) {
      cameraController.stop();
      print("Lifecycle stop is call....");
    } else if (state == AppLifecycleState.resumed) {
      startCamera();
      print("Lifecycle resume is call....");
    }
  }

  Future<void> startCamera() async {
    if (cameraController != null) {
      await cameraController.start();
    }
  }

  void resetScanner() async {
    await cameraController.stop();
    await Future.delayed(const Duration(milliseconds: 500)); // Wait for the scanner to stop
    await cameraController.start();
  }

UI:

MobileScanner(
                                fit: BoxFit.fill,
                                controller: MobileScannerController(detectionSpeed: DetectionSpeed.noDuplicates),
                                onDetect: (capture) {
                                  print("-->>" + capture.barcodes.toString());
                                  final List<Barcode> barcodes = capture.barcodes;
                                  for (final barcode in barcodes) {
                                    if (barcode.rawValue != null) {
                                      print("Barcode value: ${barcode.rawValue!}");
                                    // Going to next screen after successfully scanned qr 
                                     } else {
                                      print("Something Wrong");
                                    }
                                  }
                                },
                              ),
@navaronbracke
Copy link
Collaborator

The black screen with (i) icon is the default error builder for the MobileScanner widget.
What error details (message + stacktrace) do you get in the MobileScannerException ? (you can inspect it using the MobileScanner.errorBuilder property)

@kcs-ravindrapatil
Copy link
Author

@navaronbracke Yes I know this is error builder but it gives the below error

MobileScannerException: code genericError, message: Called start() while already started

@navaronbracke
Copy link
Collaborator

Aha, I see. Does this happen after you grant permissions?

I have a fix in progress for the underlying "Called start() while already started" error.
The fix would just ignore the second attempt at calling start, if the controller has been started before.
We do a similar thing for the stop method (not trying to stop when already stopped)

@kcs-ravindrapatil
Copy link
Author

kcs-ravindrapatil commented May 28, 2024

@navaronbracke I understand, waiting for solving the issue.

In my case for below steps:

  1. When I am scanning it 1st time it will working well and redirect to next(result) screen
  2. When am back from result screen it work for scanning the QR but camera is hide
  3. If am go back to all screens and scan it again the camera is not display and not scanning
  4. When am restart or kill the app then above issue has been faced.

@nkesarwani7
Copy link

i'm also facing this same issue, here is small demo video:
https://drive.google.com/file/d/1oL6nkTKZ8rPatdIuFLGE8WIYQyxl4Egm/view?usp=sharing

@navaronbracke
Copy link
Collaborator

If anyone that has an iOS device available is willing to test #1086 to see if it works on iOS, that would be helpful. I'm currently without an iOS device to test with, but otherwise this patch is ready to land. I'll try to get an iOS device on monday to see if I can test it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants