Using @capgo/capacitor-flash
Capacitor Flash Plugin for controlling device flashlight/torch.
Install
bun add @capgo/capacitor-flash
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { CapacitorFlash } from '@capgo/capacitor-flash';
API at a glance
| Method | Description |
|---|---|
isAvailable |
Checks if flashlight is available on the device. |
switchOn |
Turns the flashlight on. |
switchOff |
Turns the flashlight off. |
isSwitchedOn |
Checks if the flashlight is currently turned on or off. |
toggle |
Toggle the flashlight on or off. |
Examples
isAvailable()
Checks if flashlight is available on the device.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.isAvailable();
if (value) {
console.log('Flashlight is available');
}
switchOn()
Turns the flashlight on.
import { CapacitorFlash } from '@capgo/capacitor-flash';
// Turn on at full brightness
await CapacitorFlash.switchOn({ intensity: 1.0 });
// Turn on at half brightness
await CapacitorFlash.switchOn({ intensity: 0.5 });
switchOff()
Turns the flashlight off.
import { CapacitorFlash } from '@capgo/capacitor-flash';
await CapacitorFlash.switchOff();
isSwitchedOn()
Checks if the flashlight is currently turned on or off.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.isSwitchedOn();
console.log('Flashlight is on:', value);
toggle()
Toggle the flashlight on or off.
import { CapacitorFlash } from '@capgo/capacitor-flash';
const { value } = await CapacitorFlash.toggle();
console.log('Flashlight toggled, now on:', value);
Full reference
Keep going from Using @capgo/capacitor-flash
If you are using Using @capgo/capacitor-flash to plan dashboard and API operations, connect it with @capgo/capacitor-flash for the implementation detail in @capgo/capacitor-flash, Getting Started for the implementation detail in Getting Started, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, and API Keys for the implementation detail in API Keys.