Closed edwintsai closed 9 months ago
I think I know what the problem might be here.
We turn on the torch if torchEnabled
is true.
However, we do not forward the torch state to the notifier.
And in toggleTorch()
we do not check the current state either.
As a workaround you could try to set the torch after the controller was started.
What we should do is the following:
@edwintsai This should have been fixed on master now. I'm currently looking into a small MLKit related issue on Android, but there should be a hotfix later today with this bug fixed.
I had upgrade to mobile_scanner 3.5.1, If I set torchEnabled : true, it's working in start the camera, but can't stop torch if I call toggleTorch.
IconButton( color: Colors.white, icon: ValueListenableBuilder( valueListenable: cameraController.torchState, builder: (context, state, child) { switch (state) { case TorchState.off: return const Icon(Icons.flash_off, color: Colors.grey); case TorchState.on: return const Icon(Icons.flash_on, color: Colors.yellow); } }, ), iconSize: 32.0, onPressed: () =>cameraController.toggleTorch(), )
...controller: MobileScannerController( formats: [BarcodeFormat.qrCode], detectionSpeed: DetectionSpeed.noDuplicates, //DetectionSpeed.normal, facing: CameraFacing.back, detectionTimeoutMs: 1000, returnImage: false, torchEnabled: false, ),