screenshot_defender

pub package Buy Me A Coffee

A Flutter plugin to block screenshots and screen recordings on Android and iOS.

Features

  • Block screenshots and screen recordings while your app is in the foreground.
  • Unblock them when they are no longer needed.
  • Supports Android and iOS.

Demo

Android iOS
Android demo iOS demo

Platform behavior

Platform Mechanism
Android Sets FLAG_SECURE on the activity window.
iOS Uses a secure UITextField layer to prevent the window contents from being captured.

Installation

Add screenshot_defender to your pubspec.yaml:

dependencies:
  screenshot_defender: ^1.0.0

Then run:

flutter pub get

Usage

Import the package:

import 'package:screenshot_defender/screenshot_defender.dart';

Create an instance and call block() / unblock():

final ScreenshotDefender screenshotBlocker = ScreenshotDefender();

// Block screenshots and screen recordings
await screenshotBlocker.block();

// Allow screenshots and screen recordings again
await screenshotBlocker.unblock();

Full example

import 'package:flutter/material.dart';
import 'package:screenshot_defender/screenshot_defender.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ScreenshotDefender screenshotBlocker = ScreenshotDefender();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin Screenshot Defender example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () async => screenshotBlocker.block(),
                child: const Text('Screenshot Defender'),
              ),
              ElevatedButton(
                onPressed: () async => screenshotBlocker.unblock(),
                child: const Text('UnBlock Screenshot'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

See the example folder for a complete working app.

Requirements

  • Flutter >=3.44.0
  • Dart >=3.7.0
  • Android minSdk 21
  • iOS 15.0+

License

This project is licensed under the MIT License - see the LICENSE file for details.