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

!!! Android error on start: called start() while already started #539

Closed Shakle closed 2 months ago

Shakle commented 1 year ago

After some update recently - wether it was Android 13 QPR 2 (March Pixel update) or Flutter 3.7.7 on first camera initialization I get this error. In Example app it also happens. Did not check on other devices. I also guess that something related to it causes a crash from time to time when disabling/enabling camera.

ℹī¸ Environment:

✅ Steps to reproduce:

  1. Grant permissions to camera
  2. Freshly open an app
  3. Open camera screen

💡 Actual result:

👍 Expected result:

tsomone commented 1 year ago

You can do the trick by reloading camera with this code,

errorBuilder: (context, error, child) { controller.stop(); controller.start(); return ScannerReloadingWidget(error: error); }

its not recommended, but its working in my case

BryceCYB commented 1 year ago

Add controller.stop(); in initState works for me.

  void initState() {
     // To fix on start error
    controller.stop();
    super.initState();
  }
sebatorresi commented 1 year ago

In my case I did

void initState() { cameraController.stop(); super.initState(); }

Ishchik commented 1 year ago

It also reproduces when hitting Hot Restart on the screen with MobileScanner and navigating back to it

arnabonetraker commented 1 year ago

@juliansteenbakker MobileScannerException: code genericError, message: Called start() while already started. mobile_scanner: ^3.2.0 on flutter: 3.7.12.

maulikchak commented 12 months ago

same issue

tologonkudaiberdiuulu commented 11 months ago

Any progress @juliansteenbakker ?

Logaritma26 commented 10 months ago

same

JoshPark1 commented 9 months ago

We are seeing the same issue on iOS. Adding controller.stop() to initState does not resolve the issue.

Blvckleg commented 8 months ago

We are seeing the same issue on iOS. Adding controller.stop() to initState does not resolve the issue.

Have you tried this?

https://github.com/juliansteenbakker/mobile_scanner/issues/589#issuecomment-1599677867

While I definitelly think instantiating a new controller everytime isn't the prettiest I ended up using the same workaround as the user who wrote the comment.

Works fine for me. Maybe this can help?

I am still hoping this is getting fixed anytime soon though.

navaronbracke commented 2 months ago

This should no longer occur with the new beta, version 5.0.0-beta.1 , as the lifecycle is now no longer managed by mobile_scanner itself, due to issues with widget tree reparenting.

cbassols commented 1 month ago

This should no longer occur with the new beta, version 5.0.0-beta.1 , as the lifecycle is now no longer managed by mobile_scanner itself, due to issues with widget tree reparenting.

I've been fighting with this issue for the last two hours in the version 5.0.0-beta.2. If I make a hot restart, I get "MobileScannerException: code genericError, message: Called start() while already started!" The only way I have to make it work is completely closing the App and reopening it.

navaronbracke commented 1 month ago

I am aware that we should handle hot reload better, we have a tracking issue for that specifically: https://github.com/juliansteenbakker/mobile_scanner/issues/773

I still need to figure out if we can intercept it internally, or provide users with guidance around the use of reassemble().