Updated 21 December 2023
Nowadays, user data security is a foremost priority. So, it is necessary to disable screenshots/ video recordings in the apps. You must have seen that a good number of apps like banking apps don’t allow you to take screenshots or record a video.
Now, let’s check how can we prevent screenshots/video recording in Flutter apps. In Flutter, we can use the flutter_windowmanager package to implement this functionality.
You may also check our Flutter app development services page.
Create a new flutter project and add this package to your project:
| 1 | flutter_windowmanager: ^0.2.0 | 
FlutterWindowManager.FLAG_SECURE: enables secure mode for the app, and disables screenshots, and screen recording.
| 1 2 3 4 5 6 7 | if (secureModeToggle == true) {                     await FlutterWindowManager.addFlags(                         FlutterWindowManager.FLAG_SECURE);                   } else {                     await FlutterWindowManager.clearFlags(                         FlutterWindowManager.FLAG_SECURE);                   } | 
You can clear and add flags according to your requirements. This package also provides several flags that help us implement functionalities.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | void main() {   runApp(const MyApp()); } class MyApp extends StatelessWidget {   const MyApp({super.key});   // This widget is the root of your application.   @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.blue,       ),       home: const MyHomePage(),     );   } } class MyHomePage extends StatefulWidget {   const MyHomePage({super.key});   @override   State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> {   bool secureMode = false;   @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: const Text("Disable Screenshot Demo"),       ),       body: Center(         child: Column(           mainAxisAlignment: MainAxisAlignment.center,           children: <Widget>[             secureMode? const Text("Secure mode is available.") : const Text("Secure mode is not available."),             ElevatedButton(                 onPressed: () async {                   final secureModeToggle = !secureMode;                   if (secureModeToggle == true) {                     await FlutterWindowManager.addFlags(                         FlutterWindowManager.FLAG_SECURE);                   } else {                     await FlutterWindowManager.clearFlags(                         FlutterWindowManager.FLAG_SECURE);                   }                   setState(() {                   secureMode = !secureMode;                   });                 },                 child: const Text("Toggle Secure Mode ")),           ],         ),       ),     );   } } | 
When the secure flag is enabled, there is a notification to show inform regarding the disabled screenshot.
There is a drawback to this package that it doesn’t support iOS and as mentioned in the documentation there is no iOS support planned or possible.
In this article, I have explained how to prevent screenshots/video recording in the Flutter app.
Thanks for reading this article.
If I got something wrong, let me know in the comments. I would love to improve.
Reference link:
https://pub.dev/packages/flutter_windowmanager
Check out these interesting flutter topics:
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.