ff_native_screenshot

Creator: coderz1093

Last updated:

Add to Cart

Description:

ff native screenshot

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 .

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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.