ss_preventer

Flutter plugin for screenshot prevention and screenshot detection stream.

Features

  • preventOn: enable screenshot prevention.
  • preventOff: disable screenshot prevention.
  • setDetectionEnabled: enable/disable screenshot detection callbacks.
  • screenshotStream: stream event when screenshot is detected.

Platform support

  • Android
    • preventOn / preventOff: supported (uses FLAG_SECURE).
    • screenshotStream: Android 14+ only (uses registerScreenCaptureCallback).
  • iOS
    • preventOn / preventOff: supported.
    • screenshotStream: supported (UIApplication.userDidTakeScreenshotNotification).

Installation

Add dependency:

dependencies:
  ss_preventer: ^0.1.2

iOS Swift Package Manager

  • Swift Package Manager metadata is included for iOS.
  • Flutter projects using this plugin with SPM need Flutter 3.41 or later.
  • CocoaPods remains supported as a fallback.

Android permission (app side)

To use screenshot detection on Android 14+, add this permission in your app's AndroidManifest.xml:

<uses-permission android:name="android.permission.DETECT_SCREEN_CAPTURE" />

Usage

import 'dart:async';

import 'package:ss_preventer/ss_preventer.dart';

StreamSubscription? subscription;

Future<void> startProtection() async {
  await SsPreventer.preventOn();
  await SsPreventer.setDetectionEnabled(true);

  subscription = SsPreventer.screenshotStream.listen((event) {
    // Handle screenshot detection.
    print('Screenshot detected at: ${event.detectedAt}');
  });
}

Future<void> stopProtection() async {
  await SsPreventer.preventOff();
  await SsPreventer.setDetectionEnabled(false);
  await subscription?.cancel();
}

iOS implementation note

This plugin follows Flutter's UISceneDelegate migration guidance for plugins and uses scene/application lifecycle registration.

Native iOS sources are packaged for both CocoaPods and Swift Package Manager.

Reference:

Example

See /example for a full sample app.

Publishing

See PUBLISHING.md.

License

See LICENSE.