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

A Flutter plugin to block screenshots and screen recording for privacy, while allowing secure screenshot capture of specific widgets.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:zo_screenshot/zo_screenshot.dart';
import 'package:zo_screenshot_example/non_secure.dart';
import 'package:zo_screenshot_example/secure_route.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: {
        "/secureRoute": (_) => SecureRoute(),
        "/nonSecureRoute": (_) => NonSecure()
      },
      navigatorObservers: [
        ZoNavigatorObserver(
          navigationStyle: NavigationStyle.namedRoute,
          secureNamedRouteList: ["/secureRoute"],
        ),
      ],
      home: ZoScreenShotWrapper(
        disableScreenShot: true,
        backgroundPreviewWidget: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [Colors.grey[300]!, Colors.grey]),
          ),
          width: double.infinity,
          height: double.infinity,
          child: Center(
            child: Icon(Icons.lock, size: 50, color: Colors.white),
          ),
        ),
        child: Scaffold(
            appBar: AppBar(
              title: const Text('Plugin example app'),
            ),
            body: Example()),
      ),
    );
  }
}

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

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  final _zoScreenshotPlugin = ZoScreenshot();

  ZoCaptureAreaController _areaController = ZoCaptureAreaController();

  void enableScreenshot() {
    _zoScreenshotPlugin.enableScreenshot();
  }

  void disableScreenShot() {
    _zoScreenshotPlugin.disableScreenShot();
  }

  @override
  void initState() {
    // TODO: implement initState
    _zoScreenshotPlugin.startScreenshotListner(screenShotcallback: () {
      print("Screenshot taken");
    });
    super.initState();
  }

  void showSnackBar(BuildContext context, String message) {
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
      content: Text(message),
      duration: Duration(seconds: 1),
    ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          SizedBox(
            width: double.infinity,
            height: 10,
          ),
          InkWell(
            onTap: () {
              // _zoScreenshotPlugin.enableScreenshot();
              // showSnackBar(context, "Screenshot enabled");

              // Navigator.push(context,
              //     MaterialPageRoute(builder: (context) => TestScreen()));

              Navigator.pushNamed(context, "/secureRoute");
            },
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text("Secure Route "),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          InkWell(
            onTap: () {
              Navigator.pushNamed(context, "/nonSecureRoute");
            },
            child: Container(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text("Non Secure Route"),
              ),
            ),
          ),
          SizedBox(
            height: 20,
          ),
          ZoCaptureArea(
            controller: _areaController,
            child: InkWell(
              onTap: () {
                _areaController.captureAndShare();
              },
              child: Container(
                width: 150,
                height: 150,
                alignment: Alignment.center,
                color: Colors.red,
                child: Text("Click"),
              ),
            ),
          )
        ],
      ),
    );
  }
}
4
likes
140
points
105
downloads

Publisher

verified publisherthezerone.com

Weekly Downloads

A Flutter plugin to block screenshots and screen recording for privacy, while allowing secure screenshot capture of specific widgets.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path_provider, plugin_platform_interface, share_plus

More

Packages that depend on zo_screenshot

Packages that implement zo_screenshot