Tuesday, September 20, 2022
HomeWordPress DevelopmentHow you can block Screenshots in your flutter app

How you can block Screenshots in your flutter app


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:

  1. 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
Enter fullscreen mode

Exit fullscreen mode

  1. and also you substitute the content material with:
class MainActivity: FlutterFragmentActivity() {
    override enjoyable configureFlutterEngine(flutterEngine: FlutterEngine) {
        window.addFlags(LayoutParams.FLAG_SECURE)
        GeneratedPluginRegistrant.registerWith(flutterEngine)
    }
}
Enter fullscreen mode

Exit fullscreen mode

this does it for Android.

For iOS:

  1. 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)
    }
  }
Enter fullscreen mode

Exit fullscreen mode

then name the brand new window extension in your software perform:

self.window.makeSecure()
Enter fullscreen mode

Exit fullscreen mode

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)
    }
  }
Enter fullscreen mode

Exit fullscreen mode

Supply: stackoverflow reply

thanks for studying, I hope this was useful.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments