Skip to content

A simple Flutter plugin to handle the device torch.

License

Notifications You must be signed in to change notification settings

StroeAndreX/torch_light

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

torch_light

A simple Flutter plugin to enable/disable the device torch light.

Plugin status

This plugin is considered in BETA stage, could potentially contain errors and API might change. Please, use it with caution.

Import the library in your Dart code

import 'package:torch_light/torch_light.dart';

Enable/disable torch

Enable and disable the device torch:

// Enable torch
TorchLight.enableTorch();

// Disable torch
TorchLight.disableTorch();

This methods can throw an error if the process could not be completed, it is recommended to wrap them like that:

// Safely enable torch and watch errors
try {
  await TorchLight.enableTorch();
} on Exception catch (_) {
  // Handle error
}

// Safely disable torch and watch errors
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
}

About

A simple Flutter plugin to handle the device torch.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 42.2%
  • Kotlin 23.1%
  • Swift 19.1%
  • Ruby 11.9%
  • Objective-C 3.7%