flutter_native_screenshot_plus 1.0.0
flutter_native_screenshot_plus: ^1.0.0 copied to clipboard
A Flutter plugin for capturing native screenshots on Android and iOS with PixelCopy support
Flutter Native Screenshot Plus πΈ #
A high-performance Flutter plugin for capturing native screenshots with PixelCopy support (Android 8.0+). Captures exactly what users see on screen.
Table of Contents #
- Features
- Installation
- Platform Setup
- Usage
- Permission Handling
- Example Project
- FAQ
- Troubleshooting
- Contributing
- License
Features β¨ #
- Native Performance: Uses platform-specific APIs (PixelCopy on Android)
- High Fidelity: Captures exactly what's displayed on screen
- Simple API: Single method call with path return
- Automatic Media Scanning: Screenshots appear in gallery immediately
- Thread-Safe: Background processing for large screenshots
Installation π§ #
Add to your pubspec.yaml
:
dependencies:
flutter_native_screenshot_plus: ^1.0.0
Then run:
flutter pub get
Platform Setup βοΈ #
Android #
- Add permissions to
android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- For Android 10+ compatibility, add to the
<application>
tag:
android:requestLegacyExternalStorage="true"
iOS #
Add to ios/Runner/Info.plist
:
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME) saves screenshots to your photo library</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) saves screenshots to your photo library</string>
Usage π #
Basic implementation:
import 'package:flutter_native_screenshot_plus/flutter_native_screenshot_plus.dart';
// Capture and save screenshot
final path = await FlutterNativeScreenshotPlus().takeScreenshot();
if (path != null) {
// Use the file path (display preview, upload, etc.)
print('Screenshot saved at: \$path');
} else {
print('Failed to capture screenshot');
}
Permission Handling π #
This plugin requires these permissions but doesn't handle runtime requests. We recommend using permission_handler:
// Example permission check
final status = await [Permission.storage, Permission.photos].request();
if (status[Permission.storage]!.isGranted) {
// Proceed with screenshot
}
Example Project π§© #
See complete implementation in the example folder. To run:
cd example
flutter run
FAQ β #
Where are screenshots saved? #
Platform | Location |
---|---|
Android | /storage/emulated/0/Android/data/<package_name>/cache |
iOS | App's Documents directory |
Why do I get black screenshots? #
- Ensure permissions are granted
- On Android, wait for UI rendering to complete:
await Future.delayed(const Duration(milliseconds: 300));
How to share the screenshot? #
Use the share_plus package:
await Share.shareXFiles([XFile(screenshotPath)]);
Troubleshooting β οΈ #
Android Errors #
- "File not found": Check if storage permissions are granted
- "Blank images": Add delay before capturing
iOS Errors #
- Missing permissions: Verify Info.plist entries
- Sandbox issues: Use app-specific directories
Contributing π€ #
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License π #
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by Sujit Chanda. Happy screenshotting! π±π₯