Skip to content

Add camera torch (flashlight) support#435

Merged
glenn-jocher merged 1 commit intoultralytics:mainfrom
paradoxsyn:main
Apr 15, 2026
Merged

Add camera torch (flashlight) support#435
glenn-jocher merged 1 commit intoultralytics:mainfrom
paradoxsyn:main

Conversation

@paradoxsyn
Copy link
Copy Markdown
Contributor

@paradoxsyn paradoxsyn commented Jan 16, 2026

this is just a quick fix to add the flashlight. im using this personally figured I'd stick it here. I won't have time to check other submissions but this was quick so.

Best

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Adds cross-platform torch (flashlight) controls to the Flutter YOLO camera view via new MethodChannel APIs. 🔦

📊 Key Changes

  • Exposes new platform channel methods: toggleTorch, setTorchMode(enabled), isTorchAvailable, and isTorchEnabled (Android + iOS).
  • Implements torch control in Android YOLOView using CameraX (enableTorch, torchState, hasFlashUnit).
  • Implements torch control in iOS YOLOView via AVCaptureDevice torch configuration (lock/unlock + max torch level).
  • Adds matching Dart controller APIs in lib/widgets/yolo_controller.dart with basic error handling and null-safe query methods.

🎯 Purpose & Impact

  • Enables end-users to turn the flashlight on/off during live camera inference, improving low-light usability. 🌙
  • Provides feature parity across Android and iOS with a consistent Flutter API surface.
  • Helps apps gracefully adapt UI by checking torch availability/state before displaying a torch button.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 16, 2026

All Contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@UltralyticsAssistant UltralyticsAssistant added enhancement New feature or request Feature labels Jan 16, 2026
@UltralyticsAssistant
Copy link
Copy Markdown
Member

👋 Hello @paradoxsyn, thank you for submitting a ultralytics/yolo-flutter-app 🚀 PR! This is an automated message—an Ultralytics engineer will review and assist soon. 🔦

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/yolo-flutter-app main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Looks clean overall. The new MethodChannel surface is wired consistently across Dart, Android (CameraX), and iOS (AVCaptureDevice), with reasonable null-safety and graceful fallbacks (e.g., returning false/null when unavailable). No clear bugs or failure cases introduced in the shown diff.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/widgets/yolo_controller.dart 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@asabri97
Copy link
Copy Markdown
Contributor

@paradoxsyn please sign the CLA

/**
* Locks the exposure at the current level.
*/
fun lockExposure() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we double check this method?

This approach isn't locking and the single path in setAutoFocusMode call cancelFocusAndMeterinng(), which resets metering back to default auto behavior. The method claims to lock but likely return to auto so the feature behaves opposite of its contract.

@damaradiprabowo
Copy link
Copy Markdown

Any update on this @paradoxsyn ?

@paradoxsyn
Copy link
Copy Markdown
Contributor Author

Sorry all, I can take a look at this over the weekend. I haven't tested the focus mode yet, that was a "nice to have" and currently the reason I developed these is on hold - but I'll get it in a good spot for the PR here.

@paradoxsyn
Copy link
Copy Markdown
Contributor Author

8DUJ1

@paradoxsyn please sign the CLA

Also I don't know what CLA? Am I missing something?

@pderrenger
Copy link
Copy Markdown
Member

Yes, the CLA is the Contributor License Agreement required before we can merge the PR; your 8DUJ1 comment won’t trigger it, so please add the standalone signature comment referenced above and the bot should take it from there, and you can review the terms in the CLA docs.

@glenn-jocher
Copy link
Copy Markdown
Member

Thanks for the contribution here. Camera-related work tends to have a wide surface area, so it takes more review than the smaller fixes, but the effort is appreciated and it does help show where users want the project to go.

@glenn-jocher
Copy link
Copy Markdown
Member

Rescoped this onto current main and force-pushed a much smaller version of the PR.

What remains:

  • one Dart controller method: setTorchMode(bool enabled)
  • Android/iOS native handling for that method
  • a small controller test and matching API doc update

What was intentionally removed:

  • tracking
  • trackId model changes
  • focus/exposure/white-balance controls
  • all other camera-control API expansion

Local verification on this cleaned branch:

  • flutter analyze
  • flutter test
  • flutter build ios --simulator --no-codesign in example/

flutter build apk --debug in example/ still fails on the existing unrelated top5Indices classification regression already present on current main; I kept that out of scope so this PR stays minimal.

The remaining merge blocker is CLA. @paradoxsyn please add this exact standalone PR comment so the bot can pass:

I have read the CLA Document and I sign the CLA

Copy link
Copy Markdown
Member

@glenn-jocher glenn-jocher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed after rescoping onto current main. This is now the minimal useful version of the feature: a single controller API wired through the native Android and iOS camera views, with the unrelated focus/exposure/tracking work removed.

Copy link
Copy Markdown
Member

@glenn-jocher glenn-jocher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed after rescoping onto current main. This is now the minimal useful version of the feature: a single setTorchMode(bool enabled) controller API wired through the native Android and iOS camera views, with the unrelated focus/exposure/tracking work removed.

@glenn-jocher glenn-jocher changed the title added camera support v1 Add camera torch (flashlight) support Apr 15, 2026
@glenn-jocher glenn-jocher merged commit 0dd09d1 into ultralytics:main Apr 15, 2026
5 checks passed
@paradoxsyn
Copy link
Copy Markdown
Contributor Author

paradoxsyn commented Apr 15, 2026 via email

@pderrenger
Copy link
Copy Markdown
Member

Thanks Derek, and sorry to hear that; this email-style reply usually won’t satisfy the CLA check, so please add the exact standalone PR comment requested above directly in GitHub so the bot can detect it and we can move this forward.

@paradoxsyn
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants