https://github.com/fluttercandies/ff_native_screenshot
A Flutter plugin to take or listen screenshot(support Platform Views) for Android and iOS with native code.
https://github.com/fluttercandies/ff_native_screenshot
Last synced: about 1 year ago
JSON representation
A Flutter plugin to take or listen screenshot(support Platform Views) for Android and iOS with native code.
- Host: GitHub
- URL: https://github.com/fluttercandies/ff_native_screenshot
- Owner: fluttercandies
- License: mit
- Created: 2022-07-16T08:40:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-20T12:20:59.000Z (about 1 year ago)
- Last Synced: 2025-04-20T13:29:51.259Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 112 KB
- Stars: 11
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# 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](https://github.com/flutter/flutter/issues/102866) .
[](https://pub.dartlang.org/packages/ff_native_screenshot) [](https://github.com/fluttercandies/ff_native_screenshot/stargazers) [](https://github.com/fluttercandies/ff_native_screenshot/network) [](https://github.com/fluttercandies/ff_native_screenshot/blob/master/LICENSE) [](https://github.com/fluttercandies/ff_native_screenshot/issues) 
## Usage
``` yaml
dependencies:
ff_native_screenshot: any
# only for android
permission_handler: any
```
## Take Screenshot
``` dart
Uint8List? data = await FfNativeScreenshot().takeScreenshot();
```
## Listen Screenshot
``` dart
@override
void initState() {
super.initState();
init();
}
Future 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 onTakeScreenshot(Uint8List? data) async {
// if it has something error
// you can call takeScreenshot
data ??= await FfNativeScreenshot().takeScreenshot();
}
}
```