Skip to main content

screen_capture_event 1.3.0 copy "screen_capture_event: ^1.3.0" to clipboard
screen_capture_event: ^1.3.0 copied to clipboard

Catch screenshot and screen recording events on Android and iOS, using the system callbacks on Android 14 and 15 and later.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:screen_capture_event/screen_capture_event.dart';

void main() {
  runApp(const MaterialApp(
    home: ExampleScreenListener(),
  ));
}

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

  @override
  State<ExampleScreenListener> createState() => _ExampleScreenListenerState();
}

class _ExampleScreenListenerState extends State<ExampleScreenListener> {
  final ScreenCaptureEvent screenListener = ScreenCaptureEvent();
  final List<String> events = [];
  String text = "Do Screenshot or Screen Record";
  bool preventScreenshot = false;

  void log(String event) {
    final time = TimeOfDay.now().format(context);
    setState(() {
      text = event;
      events.insert(0, "$time  $event");
    });
  }

  @override
  void initState() {
    screenListener.addScreenRecordListener((recorded) {
      log(recorded ? "Start Recording" : "Stop Recording");
    });
    screenListener.addScreenShotListener((filePath) {
      log(filePath.isEmpty
          ? "Screenshot taken"
          : "Screenshot stored on : $filePath");
    });
    screenListener.watch();
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Example Screen Capture Event")),
      body: ListView(
        padding: const EdgeInsets.all(30),
        children: [
          Text(text, textAlign: TextAlign.center),
          const SizedBox(height: 10),

          ///Prevent Button
          TextButton(
            style: TextButton.styleFrom(
                backgroundColor: Theme.of(context).primaryColor),
            onPressed: () {
              setState(() {
                preventScreenshot = !preventScreenshot;
              });
              screenListener.preventAndroidScreenShot(preventScreenshot);
            },
            child: Text(
              preventScreenshot
                  ? "Allow Screenshot (ANDROID)"
                  : "Prevent Screenshot (ANDROID)",
              style: const TextStyle(color: Colors.white),
            ),
          ),

          ///Check Record Button
          TextButton(
            style: TextButton.styleFrom(
                backgroundColor: Theme.of(context).primaryColor),
            onPressed: () {
              screenListener.isRecording().then((value) {
                log(value ? "You're Still Recording" : "You're not recording");
              });
            },
            child: const Text(
              "Check Record Status",
              style: TextStyle(color: Colors.white),
            ),
          ),
          const SizedBox(height: 20),
          Text("Events (${events.length})"),
          for (final event in events) Text(event),
        ],
      ),
    );
  }
}
107
likes
160
points
20.6k
downloads

Documentation

API reference

Publisher

verified publishernizwar.dev

Weekly Downloads

Catch screenshot and screen recording events on Android and iOS, using the system callbacks on Android 14 and 15 and later.

Repository (GitHub)
View/report issues

Topics

#screenshot #screen-recording #security #privacy

License

MIT (license)

Dependencies

flutter

More

Packages that depend on screen_capture_event

Packages that implement screen_capture_event