screenshot_detect_plugin_flutter

Last updated:

0 purchases

screenshot_detect_plugin_flutter Image
screenshot_detect_plugin_flutter Images
Add to Cart

Description:

screenshot detect plugin flutter

screenshot_detect_plugin_flutter #

A simple package to detect user screenshots and get path images for Android and IOS.
You can share image to social...
Hope to help you.

Source
Pub.dev


Getting Started #
ANDROID

Required minSdkVersion >= 26, targetSdk 33
Add to AndroidManifest user permission

<!-- For sdk < 33 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<!-- For sdk >= 33 -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
copied to clipboard

For android 10 add requestLegacyExternalStorage to

<activity
....
android:requestLegacyExternalStorage="true">
</activity>
copied to clipboard

IOS

Required IOS > 14
Add NSPhotoLibraryUsageDescription to Info.plits

<key>NSPhotoLibraryUsageDescription</key>
<string>This app requires access to the photo library.</string>
copied to clipboard

USE
You can to check and request permission checkPermission.
Future<void> _checkPermission() async {
_screenshotDetect.checkPermission().then((isGranted) {
if (isGranted == null || !isGranted) {
_screenshotDetect.requestPermission();
}
});
}
copied to clipboard

Create Stream of Screenshot stream and listen call back path
Future<void> _listenScreenShot() async {
_stream = _screenshotDetect.screenShotStream();

_stream.listen((String? path) {
print("It's a screenshot of the path!\n $path");
}).onError((error) {
print("It's somethings wrong: \n $error");
});
}
copied to clipboard
Full example
import 'package:screenshot_detect_plugin_flutter/screenshot_detect.dart';

class _MyAppState extends State<MyApp> {
final ScreenshotDetect _screenshotDetect = ScreenshotDetect();
late Stream<String?> _stream;

@override
void initState() {
super.initState();
_checkPermission();
_listenScreenShot();
}

Future<void> _checkPermission() async {
_screenshotDetect.checkPermission().then((isGranted) {
if (isGranted == null || !isGranted) {
_screenshotDetect.requestPermission();
}
});
}

Future<void> _listenScreenShot() async {
_stream = _screenshotDetect.screenShotStream();

_stream.listen((String? path) {
print("It is a path screenshot!\n $path");
}).onError((error) {
print("It is somethings wrong: \n $error");
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Screenshot example app'),
),
body: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Running on: $_platformVersion\n'),
StreamBuilder<String?>(
stream: _stream,
builder: (_, AsyncSnapshot<String?> snapshoot) {
if (snapshoot.data == null) {
return const Text('Let\'s take screenShot now!');
}
return SizedBox(
width: 200,
height: 200,
child: Image.file(File(snapshoot.data!)));
},
),
],
),
),
),
);
}
}

...
copied to clipboard
Author #

tvanhuu • [email protected]

License #
MIT

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.