You don't need to do anything right now, just wait until the end, The idea is that we'll simply use the flutter_windowmanager
package to achieve this for Android.
flutter pub add flutter_windowmanager
FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);
- Then, open your project in Xcode and go to Runner to create a Swift file, for example, prevent.swift
.
ScreenRecordHandler.shared.configure()
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Prevent screenshots and recording
ScreenRecordHandler.shared.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
- Do the same -> create a Dart file wherever you want inside the lib
folder and put this code inside it.
final ScreenRecordHandlerChannel screenRecordHandlerChannel = ScreenRecordHandlerChannel();
@override
void initState() {
screenRecordHandlerChannel.preventScreenRecord();
super.initState();
}
@override
void dispose() {
screenRecordHandlerChannel.disposePreventScreenRecord();
super.dispose();
}