npm.io
9.0.0 • Published 2d ago

@capgo/capacitor-flash

Licence
MPL-2.0
Version
9.0.0
Deps
0
Size
75 kB
Vulns
0
Weekly
0
Stars
25

capacitor-flash

Turn the device flashlight on and off from your Capacitor app, with brightness control where the hardware allows it.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

Get started for free

14-day unlimited free trial. No credit card required

Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-flash in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-flash to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-flash for Capacitor apps

Built and maintained with AI

We build, improve and fix our plugins with heavy use of AI, so issues usually get fixed in under a day and pull requests get feedback the same day. A human still reviews, tests and merges 50+ pull requests daily.

  • Most plugin issues get a fix pull request the same day, often within a couple of hours, and are usually resolved in one to two days.
  • Every pull request goes through our AI review system, usually within minutes.
  • Our AI pre-checks tests, code review, conventions and security, then a human reviews, tests and merges.
  • A human, Martin, reviews, tests and merges 50+ pull requests every day.
  • In the last 90 days, 95% of plugin issues were resolved.

Learn more about how we build with AI

Key features

  • On and off: switchOn({}), switchOff() and toggle().
  • Intensity: pass intensity to switchOn() on supported devices.
  • State: isSwitchedOn() reports whether the torch is on.
  • Availability: isAvailable() checks for a flashlight first.
  • Platforms: iOS, Android and Web. iOS uses AVFoundation, Android uses Camera2. Web uses the camera torch where the browser allows it.

Why Capacitor Flash?

A simple, free, and lightweight flashlight control plugin:

  • Intensity control - Adjust brightness levels (iOS and Android 13+)
  • Status checking - Query flashlight availability and current state
  • Toggle support - Simple on/off switching with toggle method
  • Universal compatibility - Works across iOS, Android, and web (Chrome on mobile devices)
  • Modern package management - Supports both Swift Package Manager (SPM) and CocoaPods (SPM-ready for Capacitor 9)
  • Zero dependencies - Minimal footprint, no bloat

Perfect for QR scanner apps, emergency torch features, camera apps, and utility tools.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/flash/

Compatibility

Plugin version Capacitor compatibility Maintained
v9.*.* v9.*.*
v8.*.* v8.*.* On demand
v7.*.* v7.*.* On demand
v6.*.* v6.*.*
v5.*.* v5.*.*

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v9 for Capacitor 9). Only the latest major version is actively maintained.

Migrating from v8 to v9

v9 of @capgo/capacitor-flash targets Capacitor 9. Update Capacitor and this plugin together, then sync the native projects:

npm install @capacitor/core@^9.0.0 @capacitor/cli@^9.0.0 @capacitor/ios@^9.0.0 @capacitor/android@^9.0.0 @capgo/capacitor-flash@^9.0.0
npx cap sync

Capacitor 9 needs Node.js 24+, iOS 16+ (Xcode 27) and Android minSdk 26 / compileSdk 37. Follow the official Capacitor 9 update guide for the app side changes.

No plugin API was removed: the JavaScript API of v9 is the same as v8.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-flash` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-flash
npx cap sync

iOS

Works out of the box

Android

Works out of the box. No permissions are required since the CameraManager.setTorchMode() API (introduced in Android 6.0) does not require camera permission.

Optionally, you can declare the flash hardware feature in your AndroidManifest.xml:

<uses-feature android:name="android.hardware.camera.flash" android:required="false" />

Web

Works in Chrome and Chromium-based browsers on mobile devices. Uses the MediaDevices API with torch constraint. Call isAvailable() first to check if torch control is supported on the current browser/device.

API

Capacitor Flash Plugin for controlling device flashlight/torch.

isAvailable()
isAvailable() => Promise<{ value: boolean; }>

Checks if flashlight is available on the device.

Returns: Promise<{ value: boolean; }>

Since: 1.0.0


switchOn(...)
switchOn(options: { intensity?: number; }) => Promise<void>

Turns the flashlight on.

Param Type Description
options { intensity?: number; } - Optional configuration including light intensity

Since: 1.0.0


switchOff()
switchOff() => Promise<void>

Turns the flashlight off.

Since: 1.0.0


isSwitchedOn()
isSwitchedOn() => Promise<{ value: boolean; }>

Checks if the flashlight is currently turned on or off.

Returns: Promise<{ value: boolean; }>

Since: 1.0.0


toggle()
toggle() => Promise<{ value: boolean; }>

Toggle the flashlight on or off.

Returns: Promise<{ value: boolean; }>

Since: 1.0.0


getPluginVersion()
getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Keywords