Skip to content

Commit

Permalink
Merge pull request #39 from fonkamloic/readMe
Browse files Browse the repository at this point in the history
chore: updated Readme
  • Loading branch information
fonkamloic authored Jul 20, 2024
2 parents 0fda76f + 6d13a73 commit f83c5ef
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 77 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
157 changes: 81 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,35 @@
<a href="https://flutter.dev/docs/development/data-and-backend/state-mgmt/options#bloc--rx"><img src="https://img.shields.io/badge/flutter-website-deepskyblue.svg" alt="Flutter Website"></a>
</p>

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<MyHomePage> 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});
Expand All @@ -78,46 +47,82 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
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
Widget build(BuildContext context) {
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: <Widget>[
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),
],
),
),
),
);
}
Expand All @@ -126,4 +131,4 @@ class _MyAppState extends State<MyApp> {

## Additional information

check out our repo for Open-Source contribution contributions
Check out our repo for Open-Source contributions. Contributions are welcome!

0 comments on commit f83c5ef

Please sign in to comment.