A Native screenshot blocking plugin for Flutter developer, with powerful event detection capabilities.
- π‘οΈ Block screenshots with customizable color overlay, blur effect, or image overlay
- πΈ Screenshot detection β listen for screenshot events with optional captured file info
- π₯ Screen recording detection β detect when screen recording starts/stops
- π Event logging β track and retrieve screenguard logs from native storage
- π§ Highly configurable β fine-tune behavior per platform with
initSettings
| Platform | Minimum Version |
|---|---|
| Flutter | β₯ 3.7.0 |
| Dart | β₯ 3.4.0 < 4.0.0 |
| iOS | β₯ 12.0 |
| Android compileSdk | 34 |
| Java | 17 |
| Android Gradle Plugin | β₯ 8.3.0 |
| Gradle wrapper | β₯ 7.6 |
Add flutter_screenguard to your pubspec.yaml:
dependencies:
flutter_screenguard: ^2.0.0Or install via CLI:
flutter pub add flutter_screenguardImportant
You must complete these steps on Android for color overlay and blur effects to work properly. v2.0.0+ no longer need to do this step!
Open android/app/src/main/AndroidManifest.xml and add ScreenGuardColorActivity inside the <application> tag:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application ...>
<activity
android:name=".MainActivity" ...>
...
</activity>
<!-- Add this β -->
<activity android:name="com.screenguard.flutter_screenguard.ScreenGuardColorActivity"
android:theme="@style/Theme.AppCompat.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
android:exported="false"
/>
</application>
</manifest>Open up [your_project_path]/android/app/src/main/res/values/styles.xml and add style Theme.AppCompat.Translucent like below
<resource>
<style name="AppTheme">your current app style theme.............</style>
+ <style name="Theme.AppCompat.Translucent">
+ <item name="android:windowNoTitle">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:colorBackgroundCacheHint">@null</item>
+ <item name="android:windowIsTranslucent">true</item>
+ <item name="android:windowAnimationStyle">@null</item>
+ <item name="android:windowSoftInputMode">adjustResize</item>
+ </style>
</resource>
import 'package:flutter_screenguard/flutter_screenguard.dart';class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final FlutterScreenguard _screenguard;
final GlobalKey _globalKey = GlobalKey();
StreamSubscription? _screenshotSub;
StreamSubscription? _recordingSub;
@override
void initState() {
super.initState();
// Pass globalKey if you plan to use registerWithBlurView
_screenguard = FlutterScreenguard(globalKey: _globalKey);
_initScreenGuard();
}
Future<void> _initScreenGuard() async {
// β Initialize settings (required before calling any register method)
await _screenguard.initSettings(
displayOverlay: true,
displayScreenguardOverlayAndroid: true,
timeAfterResume: 2000,
);
// Listen for screenshot events
_screenshotSub = _screenguard.onScreenshotCaptured.listen((event) {
debugPrint('Screenshot captured: $event');
});
// Listen for screen recording events
_recordingSub = _screenguard.onScreenRecordingCaptured.listen((event) {
debugPrint('Recording event: $event');
});
// β£ Activate screen protection (pick one)
await _screenguard.register(color: Colors.black);
}
@override
void dispose() {
_screenguard.unregister();
_screenshotSub?.cancel();
_recordingSub?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return RepaintBoundary(
key: _globalKey, // Required for blur effect
child: Scaffold(
body: Center(child: Text('Protected Content')),
),
);
}
}Note
You must call initSettings() before any register* method, or an exception will be thrown.
Initialize the screen guard with configuration options. Must be called first.
await _screenguard.initSettings(
enableCapture: false,
enableRecord: false,
enableContentMultitask: false,
displayOverlay: false,
displayScreenguardOverlayAndroid: true,
timeAfterResume: 1000,
getScreenshotPath: false,
limitCaptureEvtCount: 0,
trackingLog: false,
);| Parameter | Type | Default | Description |
|---|---|---|---|
enableCapture |
bool? |
false |
Enable screenshot capture detection |
enableRecord |
bool? |
false |
Enable screen recording detection |
enableContentMultitask |
bool? |
false |
Show content in multitask/app switcher (iOS only) |
displayOverlay |
bool? |
false |
Display overlay when user captures the screen (iOS only) |
displayScreenguardOverlayAndroid |
bool? |
true |
Display overlay when returning from background (Android only) |
timeAfterResume |
int? |
1000 |
Delay (ms) before the overlay disappears when returning to the app |
getScreenshotPath |
bool? |
false |
Include file path in screenshot event data |
limitCaptureEvtCount |
int? |
0 |
Max number of screenshot events to trigger (0 = unlimited) |
trackingLog |
bool? |
false |
Save events to native storage for later retrieval |
Activate screen protection with a solid color overlay.
await _screenguard.register(color: Colors.red);await _screenguard.register(color: Color(0xFFFFFC31));| Parameter | Type | Required | Description |
|---|---|---|---|
color |
Color |
β | Background color for the protection overlay |
Activate screen protection with a blurred snapshot of the current screen.
Important
You must wrap your root widget with RepaintBoundary and pass its GlobalKey to FlutterScreenguard (via constructor or method parameter).
// GlobalKey provided in constructor
await _screenguard.registerWithBlurView(radius: 25);
// Or provide GlobalKey per-call
await _screenguard.registerWithBlurView(radius: 25, globalKey: myKey);| Parameter | Type | Required | Description |
|---|---|---|---|
radius |
num |
β | Blur radius. Recommended range: 15β50 |
globalKey |
GlobalKey? |
β | Override the key passed in the constructor |
Tip
A radius below 15 is too subtle β content remains readable. Above 50 is overkill β content shrinks and disappears. The sweet spot is 15β50.
Activate screen protection with a custom image overlay.
Uses SDWebImage on iOS and Glide on Android for fast loading and caching.
await _screenguard.registerWithImage(
uri: 'https://example.com/logo.png',
width: 150,
height: 300,
alignment: Alignment.center,
color: Colors.black,
);| Parameter | Type | Required | Description |
|---|---|---|---|
uri |
String |
β | URL of the image to display |
width |
double |
β | Width of the image |
height |
double |
β | Height of the image |
color |
Color? |
β | Background color (default: Colors.black) |
alignment |
Alignment? |
β | Image position using Flutter Alignment constants |
top |
double? |
β | Custom top position |
left |
double? |
β | Custom left position |
bottom |
double? |
β | Custom bottom position |
right |
double? |
β | Custom right position |
Note
alignment takes priority over manual positioning (top, left, bottom, right). Set alignment to null if you want to use custom positions.
Activate screen protection without any visual overlay. (Android only)
await _screenguard.registerWithoutEffect();Deactivate all screen protection and clean up.
await _screenguard.unregister();A Stream<Map<String, dynamic>> that emits events when a screenshot is captured.
_screenguard.onScreenshotCaptured.listen((event) {
debugPrint('Screenshot: $event');
// event may contain: path, name, type (if getScreenshotPath is enabled)
});A Stream<Map<String, dynamic>> that emits events when screen recording starts or stops.
_screenguard.onScreenRecordingCaptured.listen((event) {
final isRecording = event['isRecording'] as bool;
debugPrint('Recording: $isRecording');
});| Key | Type | Description |
|---|---|---|
isRecording |
bool |
true = recording started, false = recording stopped |
activationStatus |
Map |
Contains method (String) and isActivated (bool) |
Retrieve stored event logs from native storage. Requires trackingLog: true in initSettings.
final logs = await _screenguard.getScreenGuardLogs(maxCount: 50);
for (final log in logs) {
debugPrint('Log: $log');
}| Parameter | Type | Required | Description |
|---|---|---|---|
maxCount |
int |
β | Maximum number of log entries to retrieve |
Navigate to Device β Trigger Screenshot in the Simulator menu (iOS 14+).
- Use an emulator with Google Play Services and install a third-party screenshot/recording app (e.g., XRecorder, AZ Screen Recorder).
- Android 12+ emulators have built-in screenshot and screen recording in the Quick Settings Panel.
| Limitation | Details |
|---|---|
| Minimum OS | Screenshot blocking requires iOS 13+ / Android 8+ |
| Single registration | Call only one register* method at a time. Call unregister() before switching |
MIT License Β© 2024 Goosebump
See LICENSE for details.



