torch_light 1.1.0 copy "torch_light: ^1.1.0" to clipboard
torch_light: ^1.1.0 copied to clipboard

A Flutter plugin to check if the device has a torch / flashlight, and to turn it on and off.

torch_light #

style: lint

A simple Flutter plugin to manage the device torch / flashlight.

Import the library in your Dart code #

import 'package:torch_light/torch_light.dart';

Check if the device has an available torch #

try {
  final isTorchAvailable = await TorchLight.isTorchAvailable();
} on Exception catch (_) {
  // Handle error
}

Enable/disable torch #

Enable and disable the device torch / flash:

try {
  await TorchLight.enableTorch();
} on Exception catch (_) {
  // Handle error
}

try {
  await TorchLight.disableTorch();
} on Exception catch (_) {
  // Handle error
}

If you want further control over the errors, you can declare explicit exceptions:

// Enable torch and manage all kind of errors
try {
  await TorchLight.enableTorch();
} on EnableTorchExistentUserException catch (e) {
  // The camera is in use
} on EnableTorchNotAvailableException catch (e) {
  // Torch was not detected
} on EnableTorchException catch (e) {
  // Torch could not be enabled due to another error
}

// Disable torch and manage all kind of errors
try {
  await TorchLight.disableTorch();
} on DisableTorchExistentUserException catch (e) {
  // The camera is in use
} on DisableTorchNotAvailableException catch (e) {
  // Torch was not detected
} on DisableTorchException catch (e) {
  // Torch could not be disabled due to another error
}
55
likes
160
pub points
95%
popularity

Publisher

verified publisherdavidserrano.io

A Flutter plugin to check if the device has a torch / flashlight, and to turn it on and off.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on torch_light