screen_capture_event_plus 1.4.0
screen_capture_event_plus: ^1.4.0 copied to clipboard
Catch screen capture (Screenshot & Screen Record) event for Android and iOS
Screen Capture Event Plus #
A Flutter plugin to detect and handle screen capture events (Screenshots & Screen Recording) for both Android and iOS. It also supports securing screens by preventing screenshots on Android and applying screen blur overlays on iOS during recording.
Features #
- Screenshot Detection: Listen for screenshot events on Android (including native Android 14+
ScreenCaptureCallback) and iOS. - Screen Recording Detection: Detect when the user starts or stops screen recording (Android & iOS).
- Screenshot & Recording Protection: Secure app content with
FLAG_SECUREon Android and dynamic blur overlay protection on iOS when screen recording is detected. - Multiple & Granular Listeners: Attach and detach callbacks (
addScreenShotListener,removeScreenShotListener, etc.) easily. - Low Overhead & Safe Execution: Offloads heavy filesystem operations to background threads on Android and uses Swift Package Manager (SPM) on iOS.
Installation #
Run this command with Flutter:
flutter pub add screen_capture_event_plus
Or add it manually to your pubspec.yaml dependencies:
dependencies:
screen_capture_event_plus: ^1.3.0
Platform Configuration #
iOS #
- Supports Swift Package Manager (SPM) and requires a minimum iOS deployment target of 13.0.
- Ensure your iOS project's deployment target is set to 13.0 or higher in Xcode.
Android #
- Uses
Activity.ScreenCaptureCallbackon Android 14 (API 34)+ for permissionless screenshot detection. - Automatically requests
READ_MEDIA_IMAGESon Android 13 (Tiramisu) andREAD_EXTERNAL_STORAGEon older Android versions when required. - Ensure your Android
minSdkVersionis at least 23 (Android 6.0).
Usage #
1. Initialize and Watch for Events #
Instantiate the listener, register your callbacks, and start watching for capture events in your stateful widget:
import 'package:screen_capture_event_plus/screen_capture_event_plus.dart';
class _MyScreenState extends State<MyScreen> {
final ScreenCaptureEvent screenListener = ScreenCaptureEvent();
String statusText = "Listening for events...";
void _onRecord(bool recorded) {
setState(() {
statusText = recorded ? "Screen Recording Started" : "Screen Recording Stopped";
});
}
void _onScreenshot(String filePath) {
setState(() {
statusText = "Screenshot detected! Path: $filePath";
});
}
@override
void initState() {
super.initState();
// 1. Listen for screen recording events (Android & iOS)
screenListener.addScreenRecordListener(_onRecord);
// 2. Listen for screenshot events
screenListener.addScreenShotListener(_onScreenshot);
// 3. Start observing events
screenListener.watch();
}
@override
void dispose() {
// Optionally remove individual listeners or call dispose() to clean up native observers
screenListener.removeScreenRecordListener(_onRecord);
screenListener.removeScreenShotListener(_onScreenshot);
screenListener.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text(statusText)),
);
}
}
2. Prevent Screenshots & Secure Screen Content #
To secure the screen content from screenshots and recording:
// Enable screenshot & recording protection (FLAG_SECURE on Android, blur overlay on iOS)
screenListener.preventScreenCapture(true);
// Disable screen protection
screenListener.preventScreenCapture(false);
Credits & Acknowledgments #
This package is an enhanced version based on the original screen_capture_event package created by Nizwar.