How to block screenshots in flutter on only one page?

Viewed 507

I was wondering how to block screenshots in flutter on only one page. I read there is a way by blocking screenshots in a flutter app, with: getWindow().addFlags(LayoutParams.FLAG_SECURE); but the way I understood it was, that when I do this, screenshots are blocked in the entire app.

So my question is, is there a way to block screenshots on only one page in the flutter app in android and IOS. On every other page screenshots should still be possible. If someone knows a solution, please share it with me, because I couldn't find any solution.

2 Answers

To answer my own question, I have found a way to achieve what I have desired. With the package: flutter_windowmanager you can add flags and also remove flags. So it was pretty simple all I had to do, was add this:

       

Future<void> secureScreen() async {
        await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
        }

to the initState of the page I wanted to protect against screenshots. And then add this to the dispose method of the page:

   

Future<void> clearSecureScreen() async {
        await FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);
      }

It is important that the page is removed from the stack otherwise dispose isn't called, but i think most people already know that.

Now we achieved the desired behavior it is now impossible to take screenshots, screen recordings in any way, as far as i know.

I hope I could help someone with my post !

You could use some sort of conditioning where you can check a boolean. If that boolean is true then screenshots are blocked otherwise they are not. You can change it to true in initState when you move to the specific screen otherwise false.

Related