The package can now be found at https://github.com/halildurmus/win32/tree/main/packages/win32_clipboard.
A modern, type-safe Dart API for accessing and managing the Windows Clipboard.
This package builds on top of the package:win32 and provides a high-level abstraction over native clipboard APIs. It eliminates the need to work directly with FFI, raw pointers, or low-level Win32 calls while preserving performance and correctness.
- Text Operations: Read and write Unicode text to the clipboard.
- File List Operations: Read and write lists of file paths to the clipboard.
- Format Inspection: Check which formats are currently available on the clipboard.
- Custom Formats: Register and use custom clipboard formats with typed data.
- Change Monitoring: Subscribe to a stream of clipboard change notifications
via
ClipboardChangeMonitorclass. - Clear Clipboard: Clear all clipboard contents in one call.
Add the package to your pubspec.yaml:
dependencies:
win32_clipboard: ^2.0.0Then import it:
import 'package:win32_clipboard/win32_clipboard.dart';// Write text to the clipboard.
Clipboard.setText('Hello, clipboard!');
// Read it back.
final text = Clipboard.getText();
print(text); // Hello, clipboard!// Write a list of file paths.
Clipboard.setFileList([
r'C:\Users\user\Documents\report.pdf',
r'C:\Users\user\Pictures\photo.png',
]);
// Read it back.
final files = Clipboard.getFileList();
print(files); // [C:\Users\user\Documents\report.pdf, ...]ClipboardChangeMonitor runs a native change-notification loop in a dedicated
isolate and surfaces updates as a broadcast stream, so it never blocks your
main isolate or event loop.
final monitor = ClipboardChangeMonitor();
await monitor.start();
// Fires whenever any clipboard content changes.
monitor.events.listen((_) => print('Clipboard changed'));
// Convenience streams that only emit when the relevant format is present.
monitor.onTextChanged.listen((text) => print('New text: $text'));
monitor.onFileListChanged.listen((files) => print('New files: $files'));
// Always close the monitor when you're done to release native resources.
await monitor.close();final format = Clipboard.registerFormat('com.example.MyFormat');
final ptr = calloc<Uint8>()..value = 42;
Clipboard.setData(ClipboardData.pointer(ptr, 1, format));
calloc.free(ptr);
// Check whether your format is available.
if (Clipboard.hasFormat(format)) {
final data = Clipboard.getData(format);
// ...
}Full API reference is available here:
Additional usage examples are located in the [example] directory.
If you encounter bugs or need additional functionality, please file an issue.