flutter_screenshot_detector 0.0.4 copy "flutter_screenshot_detector: ^0.0.4" to clipboard
flutter_screenshot_detector: ^0.0.4 copied to clipboard

A Flutter plugin that emits an event when the user takes a screenshot on Android or iOS.

example/lib/main.dart

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

import 'package:flutter_screenshot_detector/flutter_screenshot_detector.dart';

void main() {
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  int _screenshotCount = 0;
  ScreenshotEvent? _lastScreenshot;
  StreamSubscription<ScreenshotEvent>? _subscription;

  @override
  void initState() {
    super.initState();
    _subscription = FlutterScreenshotDetector.instance.onScreenshot.listen((
      event,
    ) {
      if (!mounted) return;
      setState(() {
        _screenshotCount++;
        _lastScreenshot = event;

      });
    });
  }

  @override
  void dispose() {
    _subscription?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final lastScreenshot = _lastScreenshot;

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Screenshot detector')),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(24),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text('Screenshots detected: $_screenshotCount'),
                if (lastScreenshot != null) ...[
                  const SizedBox(height: 12),
                  Text(
                    'Last platform: ${lastScreenshot.platform ?? 'unknown'}',
                  ),
                  Text('Last time: ${lastScreenshot.timestamp}'),
                ],
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
311
downloads

Documentation

API reference

Publisher

verified publisherpinz.dev

Weekly Downloads

A Flutter plugin that emits an event when the user takes a screenshot on Android or iOS.

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_screenshot_detector

Packages that implement flutter_screenshot_detector