setFlashMode static method
Set camera flash mode
Implementation
static Future<bool> setFlashMode(FlashMode mode) async {
if (_cameraController != null && _cameraController!.value.isInitialized) {
try {
await _cameraController!.setFlashMode(mode);
return true;
} catch (e) {
print('Flash mode not supported: $e');
// If torch mode fails, set to off mode
if (mode == FlashMode.torch) {
try {
await _cameraController!.setFlashMode(FlashMode.off);
} catch (_) {
// If even setting to off fails, just ignore
}
}
return false;
}
}
return false;
}