mobile_scanner
mobile_scanner copied to clipboard
Camera still active even if scanner widget is not visible.
Hello. Thanks for this great package!
There is one case I'm trying to resolve: If QR code is scanned - redirect a user to the next screen. If I push the next screen, the scanner is still active. I've tried to stop the scanner like this:
@override
void didPushNext() {
controller.stop();
}
It solves the problem and the scanner is inactive if another screen is on top.
But If the app goes in the background, and then comes back to the foreground didChangeAppLifecycleState is fired and the scanner becomes active again even if the scanner is not visible (because it is covered by another screen).
Unfortunately, I can't just replace the scanner with the next screen because I want to have the ability to come back to that screen.
To resolve this issue I do CustomController(autoStart: false) and handle the lifecycle manually.
But in this case, I also need to take care of exceptions that might occur during the controller.start,
and my didChangeAppLifecycleState method looks like duplicated from the library.
Could you advise if there is a better way to resolve this issue?
We have a new big release planned, that removes the didChangeAppLifecycle() handling from the MobileScanner widget, as it causes issues with widget reparenting. Due to that change, you'll have to manually start/stop the scanner.
Would this be sufficient to help your use case? For your information, that release is currently still on my branch here https://github.com/navaronbracke/mobile_scanner/tree/mobile_scanner_platform_interface
You could use a git dependency to opt into it for now, until we create a release with it.