https://github.com/thecodedaniel/screenshot_guard
Screenshot Guard is a Flutter plugin that provides platform-specific functionality to detect and restrict screenshots and screen recording in your Flutter applications
https://github.com/thecodedaniel/screenshot_guard
dart flutter package
Last synced: 3 months ago
JSON representation
Screenshot Guard is a Flutter plugin that provides platform-specific functionality to detect and restrict screenshots and screen recording in your Flutter applications
- Host: GitHub
- URL: https://github.com/thecodedaniel/screenshot_guard
- Owner: TheCodeDaniel
- License: mit
- Created: 2024-12-23T22:47:45.000Z (about 1 year ago)
- Default Branch: dev
- Last Pushed: 2025-01-22T20:04:50.000Z (about 1 year ago)
- Last Synced: 2025-01-22T20:30:05.358Z (about 1 year ago)
- Topics: dart, flutter, package
- Language: C++
- Homepage: https://pub.dev/packages/screenshot_guard
- Size: 77.1 KB
- Stars: 29
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Screenshot Guard
`Screenshot Guard` is a Flutter plugin that provides platform-specific functionality to detect and restrict screenshots or screen recording in your Flutter applications.
## Features
- 🚫 Prevent users from taking screenshots.
- 📹 Detect and react to screen recording activity.
- 📱 Supports both Android and iOS platforms.
- 💻 Supports Windows desktop platform.
---
## Installation
1. Add the package to your `pubspec.yaml` file:
```yaml
dependencies:
screenshot_guard: ^
```
2. Run the `flutter pub get` to fetch the package.
## Usage
### Import the Package
Add the following import statement at the top of your Dart file:
```dart
import 'package:screenshot_guard/screenshot_guard.dart';
import 'package:flutter/material.dart';
import 'package:screenshot_guard/screenshot_guard.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ScreenshotGuardExample(),
);
}
}
class ScreenshotGuardExample extends StatefulWidget {
@override
_ScreenshotGuardExampleState createState() => _ScreenshotGuardExampleState();
}
class _ScreenshotGuardExampleState extends State {
bool isProtected = false;
final _screenshotGuardPlugin = ScreenshotGuard();
void toggleProtection() async {
if (isProtected) {
_screenshotGuardPlugin.enableSecureFlag(false);
} else {
_screenshotGuardPlugin.enableSecureFlag(true);
}
setState(() {
isProtected = !isProtected;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Screenshot Guard Example')),
body: Center(
child: ElevatedButton(
onPressed: toggleProtection,
child: Text(isProtected ? 'Disable Protection' : 'Enable Protection'),
),
),
);
}
}
```
## Platform Specific Details
### Android
- The plugin uses Android's `FLAG_SECURE` to prevent screenshots and screen recordings
- Ensure you have the necessary permissions in your `AndroidManifest.xml`.
### IOS
- The plugin uses iOS system notifications to detect screenshot and screen recording activities.
### Windows
- The plugin uses the Windows SetWindowDisplayAffinity API to prevent screen capture and video recording.
- The `SetWindowDisplayAffinity` API is specific to windows with the `WS_OVERLAPPEDWINDOW` style. Make sure your window meets this requirement.
- In case of failure, the error returned can be checked in the logs to diagnose issues related to display affinity.
## API Reference
### Methods
`enableSecureFlag(bool enable)`
- Description: Enables or disables the secure flag to control screenshot and screen recording
- Parameters:
`enable`: A boolean (`true` to enable protection, `false` to disable it).
- Returns: A `Future`
# Contributions
Contributions are welcome! Feel free to create issues or submit pull requests to improve this plugin.