ff_native_screenshot 1.0.0 copy "ff_native_screenshot: ^1.0.0" to clipboard
ff_native_screenshot: ^1.0.0 copied to clipboard

A Flutter plugin to take or listen screenshot(support Platform Views) for Android and iOS with native code.

ff_native_screenshot #

A Flutter plugin to take or listen screenshot(support Platform Views) for Android and iOS with native code.

It's a workaround for the issue RepaintBoundary can't take screenshot of Platform Views .

pub package GitHub stars GitHub forks GitHub license GitHub issues flutter-candies

Usage #

dependencies:
  ff_native_screenshot: any
  # only for android
  permission_handler: any
copied to clipboard

Take Screenshot #

Uint8List? data = await FfNativeScreenshot().takeScreenshot();
copied to clipboard

Listen Screenshot #


  @override
  void initState() {
    super.initState();
    init();
  }

  Future<void> init() async {
    if (Platform.isAndroid) {
      await Permission.storage.request();
    }
    FfNativeScreenshot().setup(ScreenshotFlutterApiImplements(context));
    await FfNativeScreenshot().startListeningScreenshot();

    if (mounted) {
      setState(() {});
    }
  }

  @override
  void dispose() {
    FfNativeScreenshot().stopListeningScreenshot();
    super.dispose();
  }

  bool? listening;
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.resumed:
        if (listening == true && !FfNativeScreenshot().listening) {
          FfNativeScreenshot().startListeningScreenshot();
        }
        break;
      case AppLifecycleState.paused:
        listening = FfNativeScreenshot().listening;
        if (listening == true) {
          FfNativeScreenshot().stopListeningScreenshot();
        }

        break;
      default:
    }
  }

  class ScreenshotFlutterApiImplements extends ScreenshotFlutterApi {
    ScreenshotFlutterApiImplements();
    @override
    Future<void> onTakeScreenshot(Uint8List? data) async {
     // if it has something error
     // you can call takeScreenshot 
     data ??= await FfNativeScreenshot().takeScreenshot();
    }
  }

copied to clipboard
12
likes
150
points
2.2k
downloads

Publisher

verified publisherfluttercandies.com

Weekly Downloads

2024.08.26 - 2025.03.10

A Flutter plugin to take or listen screenshot(support Platform Views) for Android and iOS with native code.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on ff_native_screenshot