when constructing extremely secured apps, it may be important to cease the consumer from taking screenshots, whereas that is fairly easy on Android, it will get slightly bit tough on the iOS half. I keep in mind going through this problem some months in the past and I scanned by way of a few StackOverflow solutions for hours, I used to be on the level of getting annoyed after I found one which was the answer for the iOS half:
For Android:
- inside your mainActivity.(java/tk), import the next:
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
import android.view.WindowManager.LayoutParams
- and also you substitute the content material with:
class MainActivity: FlutterFragmentActivity() {
override enjoyable configureFlutterEngine(flutterEngine: FlutterEngine) {
window.addFlags(LayoutParams.FLAG_SECURE)
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
this does it for Android.
For iOS:
- in your AppDelegate.swift it’s best to create a window extension similar to beneath:
extension UIWindow {
func makeSecure() {
let area = UITextField()
area.isSecureTextEntry = true
self.addSubview(area)
area.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
area.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(area.layer)
area.layer.sublayers?.first?.addSublayer(self.layer)
}
}
then name the brand new window extension in your software perform:
self.window.makeSecure()
your AppDelegate.swift ought to seem like this:
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.window.makeSecure()
GeneratedPluginRegistrant.register(with: self)
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
}
}
extension UIWindow {
func makeSecure() {
let area = UITextField()
area.isSecureTextEntry = true
self.addSubview(area)
area.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
area.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(area.layer)
area.layer.sublayers?.first?.addSublayer(self.layer)
}
}
Supply: stackoverflow reply
thanks for studying, I hope this was useful.