screen_capture_event_plus 1.4.0 copy "screen_capture_event_plus: ^1.4.0" to clipboard
screen_capture_event_plus: ^1.4.0 copied to clipboard

Catch screen capture (Screenshot & Screen Record) event for Android and iOS

example/lib/main.dart

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

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

class ExampleScreenListener extends StatefulWidget {
  const ExampleScreenListener({Key? key}) : super(key: key);

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

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

  void _onRecord(bool recorded) {
    setState(() {
      text = recorded ? "Start Recording" : "Stop Recording";
    });
  }

  void _onScreenshot(String filePath) {
    setState(() {
      text = "Screenshot detected: $filePath";
    });
  }

  @override
  void initState() {
    super.initState();
    screenListener.addScreenRecordListener(_onRecord);
    screenListener.addScreenShotListener(_onScreenshot);
    screenListener.watch();
  }

  @override
  void dispose() {
    screenListener.removeScreenRecordListener(_onRecord);
    screenListener.removeScreenShotListener(_onScreenshot);
    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.preventScreenCapture(preventScreenshot);
            },
            child: Text(
              preventScreenshot
                  ? "Allow Screenshot & Recording"
                  : "Prevent Screenshot & Recording",
              style: const TextStyle(color: Colors.white),
            ),
          ),

          ///Check Record Button
          TextButton(
            style: TextButton.styleFrom(
                backgroundColor: Theme.of(context).primaryColor),
            onPressed: () {
              screenListener.isRecording().then((value) {
                setState(() {
                  if (value) {
                    text = "You're Still Recording";
                  } else {
                    text = "You're not recording";
                  }
                });
              });
            },
            child: const Text(
              "Check Record Status",
              style: TextStyle(color: Colors.white),
            ),
          ),
        ],
      ),
    );
  }
}
0
likes
160
points
65
downloads

Documentation

API reference

Publisher

verified publisherrizkyghofur.my.id

Weekly Downloads

Catch screen capture (Screenshot & Screen Record) event for Android and iOS

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on screen_capture_event_plus

Packages that implement screen_capture_event_plus