From a8433d7b51d9dacbd784f06624f35bdd58321242 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Fonkam?=
Date: Sat, 20 Jul 2024 18:15:15 -0400
Subject: [PATCH 1/4] updated Readme
---
README.md | 157 ++++++++++++++++++++++++++++--------------------------
1 file changed, 81 insertions(+), 76 deletions(-)
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!
From ee2e4ddffa4f53db2f7222051703f500e1f181ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Fonkam?=
Date: Sat, 20 Jul 2024 18:16:55 -0400
Subject: [PATCH 2/4] cicd
---
.github/workflows/main.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index 759a05e..36de1af 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -12,4 +12,4 @@ 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"
+ # exclude: "lib/no_screenshot_platform_interface.dart lib/no_screenshot_method_channel.dart"
From 690eb4565a690adead76197a71120559ad53a760 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Fonkam?=
Date: Sat, 20 Jul 2024 18:23:29 -0400
Subject: [PATCH 3/4] cicd
---
.github/workflows/main.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index 36de1af..fc68e90 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -11,5 +11,9 @@ jobs:
with:
flutter_channel: stable
flutter_version: 3.22.3
+ # name: Very Good Coverage
+ # uses: VeryGoodOpenSource/very_good_coverage@v2
+ # with:
+ path: '/coverage/lcov.info'
min_coverage: 75
# exclude: "lib/no_screenshot_platform_interface.dart lib/no_screenshot_method_channel.dart"
From 6d13a732e9a94600518d3978e41b5644510d2205 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Fonkam?=
Date: Sat, 20 Jul 2024 18:25:38 -0400
Subject: [PATCH 4/4] cicd
---
.github/workflows/main.yaml | 5 -----
1 file changed, 5 deletions(-)
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index fc68e90..ae4990d 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -11,9 +11,4 @@ jobs:
with:
flutter_channel: stable
flutter_version: 3.22.3
- # name: Very Good Coverage
- # uses: VeryGoodOpenSource/very_good_coverage@v2
- # with:
- path: '/coverage/lcov.info'
min_coverage: 75
- # exclude: "lib/no_screenshot_platform_interface.dart lib/no_screenshot_method_channel.dart"