A plugin to enable or disable the torch of a device that works both on Android (including Android 4.x) and ioS.
Some older Android devices have been known to crash when requesting access to the device torch. This is the result of a bug on those devices requiring full camera access in order to control the camera flash.
This plugin by default only requests android.permission.FLASHLIGHT
, but if you need your app to be compatible with more devices, you can add the following lines to your application's AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
First import the library to your project in your pubspec.yaml
:
torch_compat: ^1.0.2
import 'package:torch_compat/torch_compat.dart';
TorchCompat.turnOn();
TorchCompat.turnOff();