GithubHelp home page GithubHelp logo

flutterplaza / no_screenshot Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 22.0 141 KB

Flutter plugin to enable, disable or toggle screenshot support in your application.

License: BSD 3-Clause "New" or "Revised" License

Kotlin 14.22% Ruby 12.47% Swift 15.57% Objective-C 3.69% Dart 54.06%

no_screenshot's Introduction

no_screenshot

Flutter plugin to enable, disable or toggle screenshot support in your application.

Features

  • Disables screenshot and screen recoding on Android and iOS
  • Enables screenshot and screen recoding on Android and iOS
  • Toggles screenshot and screen recoding on Android and iOS

Getting started

If you want to prevent user from taking screenshot or recording of your app. You can turn off the screenshot support from the root didChangeAppLifecycleState method.

    class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
    final _noScreenshot = NoScreenshot();

  AppLifecycleState? _notification; 
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
      case AppLifecycleState.resumed, :
        print("app in resumed");
        if(app_secure) _noScreenshot.screenshotOff();
        break;
      case AppLifecycleState.inactive:
        print("app in inactive");
        if(app_secure) _noScreenshot.screenshotOff();

        break;
      case AppLifecycleState.paused:
        print("app in paused");
        if(app_secure) _noScreenshot.screenshotOff();
        break;
      case AppLifecycleState.detached:
        print("app in detached");
        break;
    }
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance?.addObserver(this);
    ...
  }

  @override
  void dispose() {
    WidgetsBinding.instance?.removeObserver(this);
    super.dispose();
  }

Usage

Add no_screenshot to your pubspec.yaml dependencies

call the singleton NoScreenshot.instance anywhere you want to use it. For instance;

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _noScreenshot = NoScreenshot.instance;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            ElevatedButton(
              child: const Text('Press to toggle screenshot'),
              onPressed: () async {
                final result = await _noScreenshot.toggleScreenshot();
                print(result);
              },
            ),
            ElevatedButton(
              child: const Text('Press to turn off screenshot'),
              onPressed: () async {
                final result = await _noScreenshot.screenshotOff();
                print(result);
              },
            ),
            ElevatedButton(
              child: const Text('Press to turn on screenshot'),
              onPressed: () async {
                final result = await _noScreenshot.screenshotOn();
                print(result);
              },
            ),
          ],
        )),
      ),
    );
  }
}

Additional information

check out our repo for Open-Source contribution contributions

no_screenshot's People

Contributors

fonkamloic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

no_screenshot's Issues

An operation is not implemented: Not yet implemented

Hello I am working with another plugin, which restarts the app at a certain time. Unfortunately the app crashes during the restart because NoScreenshot throws an error. Could you maybe fix the error?

 kotlin.NotImplementedError: An operation is not implemented: Not yet implemented
        at com.flutterplaza.no_screenshot.NoScreenshotPlugin.onDetachedFromActivity(NoScreenshotPlugin.kt:81)

feat: Create a screen recording stream method

Description

Create a Stream, which emits a boolean based on the state of the screen being recorded or not.

This function is a useful way to determine if the user is currently recording the screen, allowing the developer to take appropriate actions, such as displaying a warning message or disabling certain features that should not be recorded.

feat: Implement feature to prevent screen shot with color

Description

Implement a feature to prevent screenshots in Android and iOS. The screenshotBlockedWithColor(Colors.green) method takes in a single argument, which is the color.
When invoked, it will display the launch image while protecting the app's data from being captured in a screenshot. This helps ensure the security of sensitive information displayed in the app, such as personal information or financial data.
It's an easy and effective way to prevent data leakage by disabling screenshots in a specific part of the app and can be useful for apps that handle sensitive information.

Crashes app when backgrounded on iOS

This package causes my iOS app to crash in the background with an exc_bad_access error:

'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x16b95bf70)
frame #0: 0x00000001d3767e38 UIKitCore-[UIView(Internal) _presentationControllerToNotifyOnLayoutSubviews] + 4 UIKitCore-[UIView(Internal) _presentationControllerToNotifyOnLayoutSubviews]:

This error is resolved when I remove the no_screenshot package from my app.

One thing to note is that it crashes on background even if it isn't being used with AppLifecycleState.

Not working in iOS

I have not tested this plugin on Android. But I was not able to disable the screenshot on iPhone X.

[โœ“] Flutter (Channel stable, 3.3.3, on macOS 13.0.1 22A400 darwin-arm, locale en-NP)
[โœ“] Xcode - develop for iOS and macOS (Xcode 14.1)

feat: Implement feature to prevent screen shot with Blur

Description

Implement a feature to prevent screenshots in Android and iOS. The screenshotBlockedWithBlur(opacity: 0.1) method takes in a single argument, which is a double ( 0>= opacity <=1) representing the opacity of the blur.
When invoked, it will display the launch image while protecting the app's data from being captured in a screenshot. This helps ensure the security of sensitive information displayed in the app, such as personal information or financial data.
It's an easy and effective way to prevent data leakage by disabling screenshots in a specific part of the app and can be useful for apps that handle sensitive information.

Able to take screenshots after app is resumed fro background

I used this package to prevent screenshots in my flutter app .
In ios after the app is sent to background , a message pops in the debug console .
message =>
[iOS][Snapshotting] Snapshotting a view that has not been rendered at least once requires afterScreenUpdates:YES.

and when the app is resumed , I was able to take screenshots.
After restarting everything was normal again.

feat: Implement feature to prevent screen shot with image

Description

Implement a feature to prevent screenshots in Android and iOS. The screenshotBlockedWithImage('LaunchImage') method takes in a single argument, which is the name of the launch image file.
When invoked, it will display the launch image while protecting the app's data from being captured in a screenshot. This helps ensure the security of sensitive information displayed in the app, such as personal information or financial data.
It's an easy and effective way to prevent data leakage by disabling screenshots in a specific part of the app and can be useful for apps that handle sensitive information.

Unable to disable screen recording on iOS

Thank you for the convenient package.

The feature says "Disables screenshot and screen recoding on Android and iOS" but I could not disable screen recording on iOS.
On Android, the screen can be disabled and a black video is saved.

Is disabling screen recording on iOS planned to be implemented?
Or am I using it incorrectly?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.