v1.1.0
torch_light
一个 Flutter 插件,用于检查设备是否具有手电筒/闪光灯,并可开启和关闭。
61喜欢 2.2万近 30 天下载150Pub 分数
AndroidiOS
一个简单的 Flutter 插件,用于控制设备手电筒。
{"sdk":"flutter"}{"sdk":"flutter"}2.8.0以下为英文项目原文快照,最新内容请访问 GitHub。
A simple Flutter plugin to manage the device torch / flashlight.
import 'package:torch_light/torch_light.dart';
try {
final isTorchAvailable = await TorchLight.isTorchAvailable();
} on Exception catch (_) {
// Handle error
}
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
}