screenshot_detector 2.0.2 copy "screenshot_detector: ^2.0.2" to clipboard
screenshot_detector: ^2.0.2 copied to clipboard

Flutter plugin that allows you to detect mobile screenshot and execute callback functions on iOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:screenshot_detector/screenshot_detector.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late ScreenshotDetector screenshotCallback;

  String text = "Ready..";

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

    init();
  }

  void init() async {
    await initScreenshotCallback();
  }

  //It must be created after permission is granted.
  Future<void> initScreenshotCallback() async {
    screenshotCallback = ScreenshotDetector();

    screenshotCallback.addListener(() {
      setState(() {
        text = "Screenshot callback Fired!";
      });
    });

    screenshotCallback.addListener(() {
      print("We can add multiple listeners ");
    });
  }

  @override
  void dispose() {
    screenshotCallback.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Detect Screenshot Callback Example'),
        ),
        body: Center(
          child: Text(text,
              style: TextStyle(
                fontWeight: FontWeight.bold,
              )),
        ),
      ),
    );
  }
}
13
likes
140
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin that allows you to detect mobile screenshot and execute callback functions on iOS and Android.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, permission_handler

More

Packages that depend on screenshot_detector

Packages that implement screenshot_detector