screenshot_callback_plus 1.0.0 copy "screenshot_callback_plus: ^1.0.0" to clipboard
screenshot_callback_plus: ^1.0.0 copied to clipboard

Flutter plugin that allows you to detect screenshot and execute callback functions.

example/lib/main.dart

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

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

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

  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  late ScreenshotCallbackPlus 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 = ScreenshotCallbackPlus();

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

    screenshotCallback.addListener(() {
      debugPrint("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: const TextStyle(
                fontWeight: FontWeight.bold,
              )),
        ),
      ),
    );
  }
}
2
likes
150
points
2.12k
downloads

Publisher

verified publishersolusibejo.com

Weekly Downloads

Flutter plugin that allows you to detect screenshot and execute callback functions.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on screenshot_callback_plus