- 导包
torch_light: 1.0.0
- 函数
Future<void> checkAndTurnOnFlash() async {
// 开
if (!lightSign) {
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
}
} else {
// 关
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
}
}
}
checkAndTurnOnFlash();