-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Added support for flash/torch mode in iOS and Android #2837
Conversation
…apturing photos and videos
…able the torch toggle if a selected camera doesn't support it
Just to clarify, all this PR does is enable torch mode which you can use as a video flash and is somewhat functional for a photo flash but as you point out it's not the same as firing the flash at the time of the photo. I didn't have any luck setting this: captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS_FLASH); I hope someone else can implement full-featured flash eventually, but for now this is the best we can do. edit |
Yeah, and I tried to improve on that but frankly there are some edge cases like some LG or Huawei phones that still work differently than what you'd expect |
I think all we can do is follow the Android API docs and implement it to that spec, and if any phone manufacturers don't implement the API correctly then there isn't much we can do about it. |
@acoutts Huge thanks for putting this out. Really looking forward to seeing this in action, there's a lot of interest in the Flutter community for shipping this feature. |
@bparrishMines is there anything I can do to help speed this along for merging? |
İf you want check this library for focus and many flash attributes (you can find ios part on the main section): |
For the scope of this PR I do not want to do anything else except torch mode like I've done here. |
@ghunkins do you know anyone I can tag here to get this reviewed / merged? Seems like it is not maintained so far.. |
Tagging reviewers on #1969 here to hopefully bring this across the finish line. Can anyone please add themselves to help review and merge this? @orestesgaolin @JoseGeorges8 @GustavoFigueira @victoralves @cyanglaz @mklim @mehmetf @bparrishMines . Thanks in advance! cc: @acoutts @NeKoFu |
As a user of the plugin I wouldn't like to see this feature implemented without proper handling of precapture measurements. It wasn't tested on variety of devices and I know that there are slight differences across manufacturers that will cause the output images to look incorrectly. Merging this to the plugin repo would mean that now the Flutter team would have to handle all the issues related to this implementation and I guess they won't be investing into that in the nearest future. Sorry to say that, but I suspect that this PR won't land in the repo as there was no interaction from the team at all. |
Just to reiterate, torch mode != flash mode. While you can indeed get by using the torch as a flash by simply turning it on/off before capturing an image, torch mode is simply the flash running constantly. The primary use case is when you need the flash turned on for the camera preview, such as for scanning QR codes, or really if you just want to build a simple flutter flashlight app. I do hope someone can add the proper flash mode in the future for image capture, but I simply want to get torch mode merged here. Let's not hold it up for something outside of the scope of the original PR. |
Hello is anyone out there? What can I do to get this merged sooner? |
cc @TahaTesser do you know anyone that can help take a look at this? Seems like there's been no activity on this plugin for the last month.. |
The Flutter team is making efforts to avoid this feature :) |
@acoutts Thanks for the contribution, is there any example code of what you did? I'd like to use the code in your branch until it gets merged. |
You can see the files changed tab here and it will show the diff of this PR: As for how to use it, that is as simple as calling |
cc @cyanglaz Hi @acoutts Thanks for the contribution! Unfortunately, this feature is non-trivial and we don't have anyone focused on adding new features to this plugin at the moment. We typically follow issue hygiene when prioritizing issues and PRs. We'll keep this on our radar, but I can't give a time frame when we'll be able to work on it. Everyone is also free to use this PR by adding a git dependency to their |
Hello, could you help me on how do I use this PR on my project? I don't know how to import it in my pubspec.yaml file, I have used by copying your code and it's working really well, thanks for that PR by the way, you saved my life :D hope the Flutter community accept your this PR soon. |
I'm a little confused. Is |
hmmmm |
Hi @acoutts |
I appreciate the effort done to get this done, but I think a camera plugin without the option to use the flash/lamp is kinda weird. I think this is a critical feature that the plugin should have... Is the PR code stable enough for use in a production APP or should we wait until it's merged? |
Thanks! |
It's been stable enough for me to use without issue so far since I created this PR months ago. |
Okay, thanks! I will give it a go and if no issue arises I will make use of it. In case I find any weird behavior or bug I will let you know. I will be keeping an eye on this, let me know if I can do anything to get this moving quicker. |
Unfortunately this plugin is not being updated for new features, so I would suggest looking to this community one for something more actively maintained: https://pub.dev/packages/camerawesome |
Nice thanks a lot! I will check that out. It's a shame it's not supported in the official plugin though 😐 |
I have tested this on about 7 devices. There seems to be some oddities upon taking a photo, where the torch on the device flashes while taking a photo, causing the image to be under exposed. This happens on every device I have tested so far but only seems to affect some (e.g. Samsung A71 running Android 10). The best test of this is if you are in a completely dark environment you can see the preview is fully lit, however the photo that comes out of the 'takePicture' function comes out completely black. |
Closing this PR in favor of #3314 |
how to use your branch in a flutter project? |
@szuwest flash and torch features on Android and iOS is available since version 0.6.3+2 of the camera plugin and is available on pub.dev. I recommend updating to the latest version 0.6.4+5. |
Thank you, I found it. |
Description
This PR implements the ability to toggle torch mode on/off in iOS and Android. You can use this to run the camera's flash continuously as a torch and can use it as a flash for photo capture (by turning it on/off before/after your capture), and during video capture as a continuous light.
It adds the following new methods to the
CameraController
:Future<bool> hasTorch()
Future<void> disableTorch()
Future<void> enableTorch()
It has been tested on an iPhone 8 running iOS 13 and a Pixel 4 running Android 29. It works during video and photo capture as well. The example app has been updated with a new toggle switch for enabling/disabling the torch. The toggle switch will be disabled (20% opacity and non-interactive) if the current selected camera does not support torch mode.
Related Issues
Closes flutter/flutter#66252
flutter/flutter#31225
flutter/flutter#58218
flutter/flutter#57307
flutter/flutter#54548
flutter/flutter#41785
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?