Prevent User To Take Screenshot In Flutter
Hello everyone.
Its an amazing task to not allow user to take a screenshot of a particular widget. It make our app more secure. In flutter, it is very easy to allow user to not to take screenshots. A package is available in flutter, which makes it easy to prevent screenshot capturing.
Let’s begin.
First you need to add a package in your pubspec.yaml file
flutter_windowmanager: ^0.0.2
get dependency
$ flutter pub get
imports
import 'package:flutter_windowmanager/flutter_windowmanager.dart';
Now using the code snippet below, you can disable the screenshots for that particular widget.
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
You can use the code inside initState().
Here's the example.
initState() {
super.initState();
_preventScreenshot();
}
Future<void> _preventScreenshot() async {
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
}
That’s all, you can use this code above for a single widget.
For reference go to this link here.
If you liked this article, don’t forget to Clap
Happy Coding !!