screen_capture_utils 1.0.1 copy "screen_capture_utils: ^1.0.1" to clipboard
screen_capture_utils: ^1.0.1 copied to clipboard

A plugin to handle screen capture events on android and ios devices

example/lib/main.dart

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

import 'package:screen_capture_utils/screen_capture_utils.dart';

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

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

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  String path = 'Unknown';
  bool guarding = false;
  late ScreenCaptureUtils screenCaptureUtils;

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

    WidgetsBinding.instance!.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance!.removeObserver(this);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        screenCaptureUtils.unGuard();
        break;
      default:
        screenCaptureUtils.guard();
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      screenCaptureUtils = ScreenCaptureUtils(
        onScreenCaptured: (_) {
          print('Captured: $_');
        },
        guardingStatus: (val) {
          print('guarding: $val');

          setState(() {
            guarding = val;
          });
        },
        onScreenCapturedWithDeniedPermission: () {
          var msg = 'onScreenCapturedWithDeniedPermission';
          print('$msg');
          setState(() {
            path = msg;
          });
        },
        oniOSScreenCaptured: (val) {
          setState(() {
            guarding = val;
          });
        },
      )..intialize();
    } catch (e) {
      print(e.toString());
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(path),
              SizedBox(
                height: 40,
              ),
              guarding == false
                  ? CupertinoButton.filled(
                      onPressed: () {
                        /// Guard Screen
                        screenCaptureUtils.guard();
                      },
                      child: Text('Guard'),
                    )
                  : CupertinoButton.filled(
                      onPressed: () {
                        /// Unguard Screen
                        screenCaptureUtils.unGuard();
                      },
                      child: Text('UnGuard'),
                    ),
            ],
          ),
        ),
      ),
    );
  }
}
19
likes
160
pub points
11%
popularity

Publisher

unverified uploader

A plugin to handle screen capture events on android and ios devices

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on screen_capture_utils