Search packages, repositories and app categories

Package detailsv2.0.0

torch_light

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

AndroidiOS
30-day downloads
26.8K
Likes
61
Pub points
160

Install package

flutter pub add torch_light

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The torch_light package is a Flutter plugin that enables developers to detect if a device has a flashlight and control its operation. It provides simple methods to check torch availability and toggle the flashlight on or off, making it ideal for apps requiring light functionality. Compatible with both Android and iOS, it leverages native device capabilities through platform channels. The plugin is lightweight and easy to integrate, offering reliable access to hardware features without additional dependencies. It's particularly useful in utility apps, emergency tools, or navigation aids where lighting control is essential.

Use cases

  • Emergency lighting in dark environments
  • Navigation apps requiring handheld light
  • Utility apps with flashlight functionality
  • Security or inspection tools
  • Simple on/off light control

Key features

  • Check if device has a torch
  • Turn flashlight on and off
  • Cross-platform support (Android & iOS)
  • Lightweight and minimal dependency
  • Simple API for quick integration

Suitable for

  • Developers building utility apps
  • Apps needing basic flashlight control
  • Mobile applications for safety or navigation
  • Projects requiring minimal hardware access
  • Flutter beginners exploring device features

Considerations

  • Requires camera permission on some devices
  • May not work on all devices without a torch
  • Limited to basic on/off functionality
  • No brightness adjustment support
  • Depends on device hardware availability

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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
}

Categories

Source repository

Projects using this package