How to Disable Screenshot Capture/Screen Recording in Flutter

In this example, we are going to make an app that prevents screenshot capture or screenshot recording its app interface. We have used the window manager Flutter package to disable screenshot capture and screen recordings.

First, you need to add flutter_windowmanager package in your project by adding the following line lines in pubspec.yaml file.

dependencies:
  flutter:
    sdk: flutter
  flutter_windowmanager: ^0.2.0

Import [ackage in the script:

import 'package:flutter_windowmanager/flutter_windowmanager.dart';

await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
//enables secure mode for app, disables screenshot, screen recording

import 'package:flutter/material.dart';
import 'package:flutter_windowmanager/flutter_windowmanager.dart';
void main() {
  runApp(
    MaterialApp( 
      home: MyApp(),
    )
  );
}

class MyApp extends StatefulWidget{
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    Future.delayed(Duration.zero, () async { //to run async code in initState
       await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
       //enables secure mode for app, disables screenshot, screen recording
    });

    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
          body: Container(
             //your app content here
          )
    );
  }
}

In this way, you can force prevent screenshot capture and screen recording for the Flutter app.

No any Comments on this Article


Please Wait...