A Flutter plugin to control the device flashlight on Android.
- Turn flashlight on/off
- Check flashlight availability
- Toggle flashlight state
Add this to your package's pubspec.yaml file:
dependencies:
flashlight_plugin: ^0.0.1import 'package:flashlight_plugin/flashlight_plugin.dart';
// Check if flashlight is available
bool hasFlash = await FlashlightPlugin.hasFlashlight();
// Turn on the flashlight
await FlashlightPlugin.turnOn();
// Turn off the flashlight
await FlashlightPlugin.turnOff();
// Toggle flashlight
await FlashlightPlugin.toggle();Add the following permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.flash" />- Android API 23 (Android 6.0) or higher
- Flutter 3.0.0 or higher
MIT License