flutter_screenshot_blocker 1.0.2 copy "flutter_screenshot_blocker: ^1.0.2" to clipboard
flutter_screenshot_blocker: ^1.0.2 copied to clipboard

A powerful Flutter plugin that prevents screenshots or shows black screen when screenshots are taken. This plugin provides **system-level protection** using native platform code.

Logo

Pub Publisher Pub Points Pub Popularity Pub Version Pub Likes

Flutter Screenshot Blocker #

A powerful Flutter plugin that prevents screenshots or shows black screen when screenshots are taken. This plugin provides system-level protection using native platform code.

🌟 Features #

  • βœ… System-Level Screenshot Blocking - Uses FLAG_SECURE on Android and secure views on iOS
  • πŸ“± Black Screen on Screenshot - When screenshots are attempted, they show black screen
  • πŸ“± Black Screen on Screen recording - Screen recordings will show black screen
  • πŸ” Screenshot Detection - Detect when users attempt to take screenshots
  • 🎯 Widget-Level Protection - Apply protection to specific parts of your app
  • πŸ”’ Secure App Wrapper - Easy-to-use app-wide protection
  • πŸ“Š Event Streaming - Real-time screenshot attempt notifications
  • πŸš€ Cross-Platform - Works on both Android and iOS
  • πŸ’ͺ Native Implementation - Maximum security with platform-specific code

πŸš€ Installation #

Add this to your pubspec.yaml:

dependencies:
flutter_screenshot_blocker: ^1.0.2

Run:

flutter pub get

πŸ“± Platform Setup #

πŸ€– Android Setup #

No additional setup required! The plugin automatically applies FLAG_SECURE to prevent screenshots. You can setup it if needed. So you can use the manifest given below

To block screenshots in your Flutter app, update the AndroidManifest.xml as shown below: (Optional)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.flutter_screenshot_blocker_example">

    <!-- (Optional) Permission for detecting screenshots -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:label="flutter_screenshot_blocker_example"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <!-- Enable FLAG_SECURE to block screenshots and screen recordings -->
            <meta-data
                android:name="flutter_screenshot_blocker.secure"
                android:value="true" />

            <!-- Flutter theme metadata -->
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />

            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

ο£Ώ iOS Setup #

No additional setup required! The plugin uses secure UITextField technique and screenshot detection. You can setup it if needed. So you can use the Info.plist given below

To enable screenshot protection and enhance app security on iOS, add the following keys to your ios/Runner/Info.plist file.

// ios/Runner/Info.plist additions
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <!-- ... existing keys ... -->

  <!-- Add screenshot protection info -->
  <key>NSPhotoLibraryUsageDescription</key>
  <string>This app needs to detect screenshots for security purposes.</string>

  <key>UIRequiredDeviceCapabilities</key>
  <array>
    <string>armv7</string>
  </array>

  <!-- Prevent screenshots in app switcher -->
  <key>UIApplicationSupportsMultipleScenes</key>
  <false/>

  <key>LSRequiresIPhoneOS</key>
  <true/>

  <!-- Security settings -->
  <key>flutter_screenshot_blocker</key>
  <dict>
    <key>enable_protection</key>
    <true/>
    <key>show_security_warning</key>
    <true/>
  </dict>
</dict>
</plist>

πŸ“– Usage #

Method 1: Secure App Wrapper (Easiest) #

Wrap your entire app with SecureApp:

void main() {
  runApp(
    SecureApp(
      enableScreenshotBlocking: true,
      showSecurityWarning: true,
      child: MyApp(),
    ),
  );
}

Method 2: Widget-Level Protection #

Protect specific widgets:

ScreenshotBlockerWidget(
    blockScreenshots: true,
    detectScreenshots: true,
    onScreenshotDetected: (event) {
      print('Screenshot blocked: ${event.type}');
      // Show your custom message
    },
    child: YourSensitiveWidget(),
  );

Method 3: Manual Control #

Control protection manually:

class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class _MyPageState extends State<MyPage> {
  @override
  void initState() {
    super.initState();
    // Enable protection when page loads
    FlutterScreenshotBlocker.enableScreenshotBlocking();
  }

  @override
  void dispose() {
    // Disable protection when leaving page
    FlutterScreenshotBlocker.disableScreenshotBlocking();
    super.dispose();
  }
}

Screenshot Detection Events #

Listen to screenshot attempts:

StreamSubscription? _screenshotSubscription;

@override
void initState() {
  super.initState();

  _screenshotSubscription = FlutterScreenshotBlocker.onScreenshotDetected
      .listen((ScreenshotEvent event) {
        switch (event.type) {
          case 'screenshot_taken':
            showDialog(
              context: context,
              builder: (_) => AlertDialog(
                title: Text('Screenshot Detected!'),
                content: Text('Screenshots are not allowed in this app.'),
                actions: [
                  TextButton(
                    onPressed: () => Navigator.pop(context),
                    child: Text('OK'),
                  ),
                ],
              ),
            );
            break;
          case 'screenshot_blocked':
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(
                content: Text('Screenshot blocked for security!'),
                backgroundColor: Colors.red,
              ),
            );
            break;
        }
      });
}

@override
void dispose() {
  _screenshotSubscription?.cancel();
  super.dispose();
}

βš™οΈ API Reference #

FlutterScreenshotBlocker Class #

Method Return Type Description
enableScreenshotBlocking() Future<bool> Enable screenshot blocking
disableScreenshotBlocking() Future<bool> Disable screenshot blocking
isScreenshotBlockingEnabled() Future<bool> Check if blocking is enabled
enableSecureMode() Future<bool> Enable secure mode
disableSecureMode() Future<bool> Disable secure mode
setSecureFlag(bool) Future<bool> Set secure flag state
enableScreenshotDetection() Future<bool> Enable screenshot detection
disableScreenshotDetection() Future<bool> Disable screenshot detection
onScreenshotDetected Stream<ScreenshotEvent> Stream of screenshot events

ScreenshotBlockerWidget Properties #

Property Type Default Description
child Widget required Widget to protect
blockScreenshots bool true Enable screenshot blocking
detectScreenshots bool true Enable screenshot detection
onScreenshotDetected Function(ScreenshotEvent)? null Screenshot event callback
blockedWidget Widget? null Custom widget when blocked

SecureApp Properties #

Property Type Default Description
child Widget required App widget
enableScreenshotBlocking bool true Enable protection
showSecurityWarning bool true Show security dialog
securityWarningMessage String? null Custom warning message

πŸ”’ How It Works #

Android Implementation #

  • Uses WindowManager.LayoutParams.FLAG_SECURE flag
  • Prevents screenshots at the system level
  • Screenshots show black screen instead of app content
  • Detects screenshot attempts via system callbacks

iOS Implementation #

  • Uses secure UITextField technique to prevent screenshots
  • Implements UIApplicationUserDidTakeScreenshotNotification for detection
  • Creates secure view layers that prevent screen capture
  • Screenshots show black/empty screen

⚠️ Important Notes #

Security Level #

This plugin provides system-level protection which means:

  • βœ… Screenshots will show black screen
  • βœ… Screen recordings will show black screen
  • βœ… App switcher will show protected content
  • ❌ Cannot prevent physical camera recording of screen
  • ❌ Cannot prevent rooted/jailbroken device bypasses

Platform Differences #

  • Android: Uses FLAG_SECURE, very effective
  • iOS: Uses secure view techniques, good protection
  • Web: Not supported (web platform limitations)

πŸ§ͺ Testing #

The plugin includes comprehensive tests. Run them with:

flutter test

To test the screenshot blocking:

  • Enable protection in the demo app
  • Try taking a screenshot
  • The screenshot should show a black screen
  • Disable protection and try again - normal screenshot

πŸ”§ Troubleshooting #

Screenshots Still Work #

  • Make sure you called enableScreenshotBlocking()
  • Check that the method returned true
  • On iOS, ensure your app is in the foreground
  • Try using SecureApp wrapper for app-wide protection

Detection Not Working #

  • Ensure enableScreenshotDetection() was called
  • Check that you're listening to the event stream
  • On Android, some devices may not support detection

Performance Issues #

  • Screenshot blocking has minimal impact
  • Detection uses system notifications, very efficient
  • Consider disabling detection if not needed

🀝 Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License #

This project is licensed under the MIT License.


🎯 Use Cases #

Perfect for:

  • 🏦 Banking Apps - Protect account numbers and balances
  • πŸ₯ Medical Apps - Secure patient information
  • πŸ’Ό Business Apps - Protect confidential documents
  • πŸ” Security Apps - Prevent sensitive data leakage
  • πŸ“± Enterprise Apps - Meet corporate security requirements

⭐ Star This Repo #

If this plugin helped you, please ⭐ star this repository!

4
likes
160
points
59
downloads
screenshot

Publisher

verified publishersanjaysharma.info

Weekly Downloads

A powerful Flutter plugin that prevents screenshots or shows black screen when screenshots are taken. This plugin provides **system-level protection** using native platform code.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_screenshot_blocker

Packages that implement flutter_screenshot_blocker