Screen Record Tracking Plugin for Flutter

Screen record tracking plugin for flutter

A flutter plugin for ios to listen to and check the screen recording status.

PlatformsiOS
Support12.0+

GET STARTED

Install

Add the flutter_prevent_screen_capture plugin to your pubspec dependencies.

Easy to use

It is possible to either check or listen to the status of screen recording.

void initState() {
    ///Though listening to the screen record, it is recommended to check the screen record status on the first launch.
    checkScreenRecord();

    ///Initialize screenRecordSubscription to regularly listen to the changes
    _screenRecordsSubscription =
        preventScreenCapture.screenRecordsIOS.listen(updateRecordStatus);
    super.initState();
}

///Cancel the subscription when the widget is disposed
@override
  dispose() {
    _screenRecordsSubscription.cancel();
    super.dispose();
  }

In order to check the screen recording status once only

Future<void> checkScreenRecord() async {
    final recordStatus = await preventScreenCapture.checkScreenRecord();

    debugPrint('Is screen being recorded: $recordStatus');

    isRecording = recordStatus;
    setState(() {});
}

Note

It works on real devices only !!

FAQ

Does it work on Android?

Currently this plugin supports only ios.

Is it possible to check this with simulator?

No, the plugin works only in real devices!

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add flutter_prevent_screen_capture

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  flutter_prevent_screen_capture: ^0.0.2

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:flutter_prevent_screen_capture/flutter_prevent_screen_capture.dart';


example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ///Define a streamSubscription in order to receive changes
  late StreamSubscription<bool> _screenRecordsSubscription;

  ///Get the instance of plugin for multiple use.
  FlutterPreventScreenCapture preventScreenCapture =
      FlutterPreventScreenCapture();

  ///is Recording is set to false initially.
  bool isRecording = false;

  @override
  void initState() {
    ///Though listening to the screen record, it is recommended to check the screen record status on the first launch.
    checkScreenRecord();

    ///Initialize screenRecordSubscription to regularly listen to the changes
    _screenRecordsSubscription =
        preventScreenCapture.screenRecordsIOS.listen(updateRecordStatus);
    super.initState();
  }

  ///Cancel the subscription when the widget is disposed
  @override
  dispose() {
    _screenRecordsSubscription.cancel();
    super.dispose();
  }

  updateRecordStatus(bool record) {
    isRecording = record;
    setState(() {});
  }

  Future<void> checkScreenRecord() async {
    final recordStatus = await preventScreenCapture.checkScreenRecord();

    debugPrint('Is screen being recorded: $recordStatus');

    isRecording = recordStatus;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Screen record check example'),
      ),
      body: Center(
        child: Text('isRecording: $isRecording'),
      ),
      floatingActionButton: FloatingActionButton(onPressed: () async {
        await checkScreenRecord();
      }),
    );
  }
} 

Download details:

Author: Blacktaler

Source: https://github.com/Blacktaler/flutter_prevent_screen_capture

#flutter #screen #capture

Screen Record Tracking Plugin for Flutter
1.65 GEEK