flutter_prevent_screen_capture 0.0.2 copy "flutter_prevent_screen_capture: ^0.0.2" to clipboard
flutter_prevent_screen_capture: ^0.0.2 copied to clipboard

PlatformiOS

Flutter plugin to track the screen recording changes. It is possible to either check the screen status once only or regularly listen to the changes.

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();
      }),
    );
  }
}
10
likes
160
points
235
downloads

Publisher

verified publisherblacktaler.uz

Weekly Downloads

Flutter plugin to track the screen recording changes. It is possible to either check the screen status once only or regularly listen to the changes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_prevent_screen_capture