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

fix: Fix torch state sync issues #842

Merged

Conversation

navaronbracke
Copy link
Collaborator

@navaronbracke navaronbracke commented Oct 31, 2023

This PR fixes a bug where the torch state was not properly synced with the notifier.
Android, iOS and MacOS use callbacks to notify when their observable torch state has changed.
However, the plugin also manually set the torch state, which made it go out-of-sync.

Changelog:

  • Instead of throwing an error during toggleTorch, if the device is null, do nothing
  • Remove some redundant print() calls, instead adding a comment why exceptions are ignored
  • Only turn the toch on for iOS/MacOS when requested and if the torch value would change the current torch state
  • Bring the iOS/MacOS toggle torch implementations closer together, while also checking the isTorchAvailable besides hasTorch for iOS. This is some work towards making Use sharedDarwinSource to share MacOS and iOS implementation details #782 easier.
  • Use error.localisedDescription as message for FlutterError, rather than putting it in the code field
  • On MacOS, like iOS, also continue the capture if the torch could not be turned on, rather than throwing an error
  • Replace a usage of containsKey() with a nullable value access in the web plugin. This reads a bit better, and provides type promotion for the variable.
  • Fixed a bug where the torch state was not set to TorchState.off when the camera is stopped
  • Fixed a bug where the torch state notifier has its value updated outside of the torch observer callback

The last two fixes listed here probably fixed the out-of-sync issue of #833

Fixes #833

@navaronbracke navaronbracke marked this pull request as ready for review October 31, 2023 12:27
@navaronbracke navaronbracke merged commit 2a8af21 into juliansteenbakker:master Oct 31, 2023
4 checks passed
@navaronbracke navaronbracke deleted the fix_torch_on_start branch October 31, 2023 12:29
joaopedro735 pushed a commit to joaopedro735/mobile_scanner that referenced this pull request Aug 22, 2024
…_on_start

fix: Fix torch state sync issues
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 this pull request may close these issues.

toggleTorch() is out of sync with the actual torch state
1 participant