✅ Error Handling: Comprehensive error handling with custom exceptions and error codes
✅ Utility Methods: Check clipboard status, size, and content type
✅ Callback Support: Success and error callbacks for operations
✅ Debug Information: Get detailed clipboard debugging info
✅ Cross-Platform: Works on Android, iOS, Web, and Windows with graceful fallbacks
✅ Null Safety: Full null safety support
✅ Memory Safe: Proper listener management with cleanup mechanisms
✅ Production Ready: Battle-tested with comprehensive error handling
Installation
Add this to your package's pubspec.yaml file:
dependencies:clipboard:^3.0.14
Platform Setup
Android
The package uses platform channels for enhanced features. No additional setup required - the package automatically falls back to Flutter's built-in Clipboard API if platform channels are unavailable.
iOS
No additional setup required. The package automatically handles platform channel registration.
Web
Fully supported with automatic fallback to browser Clipboard API.
Windows
No additional setup required. The package uses native Windows API with GDI+ for image support. Platform channels are automatically registered.
import'dart:typed_data';
import'package:flutter/services.dart';
// Copy image to clipboardfinalByteData imageData = await rootBundle.load('assets/image.png');
finalUint8List imageBytes = imageData.buffer.asUint8List();
awaitFlutterClipboard.copyImage(imageBytes);
// Paste image from clipboardfinalUint8List? pastedImage = awaitFlutterClipboard.pasteImage();
if (pastedImage != null) {
// Use the image bytes (e.g., display in Image.memory)Image.memory(pastedImage);
}
// Images are also included in pasteRichText()final data = awaitFlutterClipboard.pasteRichText();
if (data.hasImage) {
print('Clipboard contains image: ${data.imageBytes?.length} bytes');
}
The package includes comprehensive testing utilities:
// Set mock data for testingawaitFlutterClipboard.setMockData('Test data');
// Get debug information for testingMap<String, dynamic> info = awaitFlutterClipboard.getDebugInfo();
Why This Enhanced Package?
I originally built this package 4 years ago for basic clipboard functionality. Over time, I realized developers needed more advanced features:
True Rich Text Support: Native HTML clipboard support via platform channels (not just in-memory storage)
Production Ready: Graceful fallbacks ensure reliability across all platforms
Modern API: Updated to latest Dart/Flutter standards with platform channel support
This enhanced version maintains backward compatibility while adding powerful new features that modern Flutter apps need. The package now uses platform channels for true multi-format support and native clipboard monitoring, with automatic fallbacks to Flutter's built-in Clipboard API when needed.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.