diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index 759a05e..ae4990d 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -12,4 +12,3 @@ jobs:
flutter_channel: stable
flutter_version: 3.22.3
min_coverage: 75
- exclude: "lib/no_screenshot_platform_interface.dart lib/no_screenshot_method_channel.dart"
diff --git a/README.md b/README.md
index b082131..e2a6e2d 100644
--- a/README.md
+++ b/README.md
@@ -8,66 +8,35 @@
-Flutter plugin to enable, disable or toggle screenshot support in your application.
+The Flutter plugin will enable, disable, or toggle screenshot support in your application.
## Features
-- Disables screenshot and screen recoding on Android and iOS
-- Enables screenshot and screen recoding on Android and iOS
-- Toggles screenshot and screen recoding on Android and iOS
+- Disables screenshot and screen recording on Android and iOS.
+- Enables screenshot and screen recording on Android and iOS.
+- Toggles screenshot and screen recording on Android and iOS.
+- Provides a stream to listen for screenshot activities.
-## Getting started
-
-If you want to prevent user from taking screenshot or recording of your app. You can turn off the screenshot support from the root `didChangeAppLifecycleState` method.
+## Update
-```dart
- class _MyHomePageState extends State with WidgetsBindingObserver {
- final _noScreenshot = NoScreenshot.instance;
+Tracking `didChangeAppLifecycleState` is no longer required. The state will be persisted automatically in the native platform SharedPreferences.
- AppLifecycleState? _notification;
- @override
- void didChangeAppLifecycleState(AppLifecycleState state) {
- case AppLifecycleState.resumed, :
- print("app in resumed");
- if(app_secure) _noScreenshot.screenshotOff();
- break;
- case AppLifecycleState.inactive:
- print("app in inactive");
- if(app_secure) _noScreenshot.screenshotOff();
-
- break;
- case AppLifecycleState.paused:
- print("app in paused");
- if(app_secure) _noScreenshot.screenshotOff();
- break;
- case AppLifecycleState.detached:
- print("app in detached");
- break;
- }
- }
-
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance?.addObserver(this);
- ...
- }
+## Getting started
- @override
- void dispose() {
- WidgetsBinding.instance?.removeObserver(this);
- super.dispose();
- }
-```
+Add `no_screenshot` to your `pubspec.yaml` dependencies.
## Usage
-Add `no_screenshot` to your `pubspec.yaml` dependencies
-
-call the singleton `NoScreenshot.instance` anywhere you want to use it.
-For instance;
+Call the singleton `NoScreenshot.instance` anywhere you want to use it. For instance:
```dart
+import 'package:flutter/material.dart';
+import 'package:no_screenshot/no_screenshot.dart';
+import 'package:no_screenshot/screenshot_snapshot.dart';
+
+void main() {
+ runApp(const MyApp());
+}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@@ -78,10 +47,21 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State {
final _noScreenshot = NoScreenshot.instance;
+ bool _isListeningToScreenshotSnapshot = false;
+ ScreenshotSnapshot _latestValue = ScreenshotSnapshot(
+ isScreenshotProtectionOn: false,
+ wasScreenshotTaken: false,
+ screenshotPath: '',
+ );
@override
void initState() {
super.initState();
+ _noScreenshot.screenshotStream.listen((value) {
+ setState(() {
+ _latestValue = value;
+ });
+ });
}
@override
@@ -89,35 +69,60 @@ class _MyAppState extends State {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
- title: const Text('Plugin example app'),
+ title: const Text('No Screenshot Plugin Example'),
),
body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: [
- ElevatedButton(
- child: const Text('Press to toggle screenshot'),
- onPressed: () async {
- final result = await _noScreenshot.toggleScreenshot();
- print(result);
- },
- ),
- ElevatedButton(
- child: const Text('Press to turn off screenshot'),
- onPressed: () async {
- final result = await _noScreenshot.screenshotOff();
- print(result);
- },
- ),
- ElevatedButton(
- child: const Text('Press to turn on screenshot'),
- onPressed: () async {
- final result = await _noScreenshot.screenshotOn();
- print(result);
- },
- ),
- ],
- )),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ ElevatedButton(
+ onPressed: () async {
+ await _noScreenshot.startScreenshotListening();
+ setState(() {
+ _isListeningToScreenshotSnapshot = true;
+ });
+ },
+ child: const Text('Start Listening'),
+ ),
+ ElevatedButton(
+ onPressed: () async {
+ await _noScreenshot.stopScreenshotListening();
+ setState(() {
+ _isListeningToScreenshotSnapshot = false;
+ });
+ },
+ child: const Text('Stop Listening'),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 10),
+ child: Text(
+ "Screenshot Streaming is ${_isListeningToScreenshotSnapshot ? 'ON' : 'OFF'}\n\nIsScreenshotProtectionOn: ${_latestValue.isScreenshotProtectionOn}\nwasScreenshotTaken: ${_latestValue.wasScreenshotTaken}\nScreenshot Path: ${_latestValue.screenshotPath}"),
+ ),
+ ElevatedButton(
+ onPressed: () async {
+ bool result = await _noScreenshot.screenshotOff();
+ debugPrint('Screenshot Off: $result');
+ },
+ child: const Text('Disable Screenshot'),
+ ),
+ ElevatedButton(
+ onPressed: () async {
+ bool result = await _noScreenshot.screenshotOn();
+ debugPrint('Enable Screenshot: $result');
+ },
+ child: const Text('Enable Screenshot'),
+ ),
+ ElevatedButton(
+ onPressed: () async {
+ bool result = await _noScreenshot.toggleScreenshot();
+ debugPrint('Toggle Screenshot: $result');
+ },
+ child: const Text('Toggle Screenshot'),
+ ),
+ const SizedBox(height: 20),
+ ],
+ ),
+ ),
),
);
}
@@ -126,4 +131,4 @@ class _MyAppState extends State {
## Additional information
-check out our repo for Open-Source contribution contributions
+Check out our repo for Open-Source contributions. Contributions are welcome!