I am making a Flutter app and I need to make sure the user is not able to capture screenshot of the app (any screen). Is there any way to achieve this in Flutter or do I need to write native code for both Android and IOS?
yaml file of your Flutter project and run pub get. Then add the below code inside the widget's initState() method for which you want to disable screenshot and screen recording. If you want to make your whole app screenshot disable just call securescreen() method (defined above) inside your main() function in main.
The Project Settings dialog box appears. From the left pane, expand the Native tab, and then select the Android Mobile/Tablet sub-tab. In the Miscellaneous section, enable the Disable Application Screenshot check box. Click Done.
There are several ways to protect your pictures: disable right-click protection, apply a watermark to your pictures, register your copyright, add a copyright notice, or enable hotlink protection.
import android.view.WindowManager.LayoutParams;
getWindow().addFlags(LayoutParams.FLAG_SECURE);
For Flutter2 project
Method 1 : using package flutter_windowmanager
Method 2 :
in Android with kotlin
Step 1 Open the file "mainActivity.kt" using the path
android\app\src\main\kotlin\com\example\auth_email\MainActivity.kt
Step 2 Import Library
import android.view.WindowManager.LayoutParams import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine
Step 3 In main activity class
class MainActivity: FlutterActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine) { window.addFlags(LayoutParams.FLAG_SECURE) super.configureFlutterEngine(flutterEngine) } }
In iOS Swift : AppDelegate.swift file
import UIKit import Flutter @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } // <Add> override func applicationWillResignActive( _ application: UIApplication ) { self.window.isHidden = true; } override func applicationDidBecomeActive( _ application: UIApplication ) { self.window.isHidden = false; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With