Skip to content
This repository was archived by the owner on Feb 26, 2026. It is now read-only.

halildurmus/win32_clipboard

This package has moved

The package can now be found at https://github.com/halildurmus/win32/tree/main/packages/win32_clipboard.


ci Package: win32_clipboard Publisher: halildurmus.dev Language: Dart License: BSD-3-Clause codecov

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.

✨ Features

  • 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 ClipboardChangeMonitor class.
  • Clear Clipboard: Clear all clipboard contents in one call.

🚀 Getting Started

Add the package to your pubspec.yaml:

dependencies:
  win32_clipboard: ^2.0.0

Then import it:

import 'package:win32_clipboard/win32_clipboard.dart';

⚡ Quick Example

Reading and writing text

// Write text to the clipboard.
Clipboard.setText('Hello, clipboard!');

// Read it back.
final text = Clipboard.getText();
print(text); // Hello, clipboard!

Reading and writing a file list

// 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, ...]

Monitoring clipboard changes

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();

Registering and using a custom format

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);
  // ...
}

📝 Documentation

Full API reference is available here:

👉 API Reference.

Additional usage examples are located in the [example] directory.

🐞 Features and Bugs

If you encounter bugs or need additional functionality, please file an issue.

About

Interact with the Windows Clipboard.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Contributors

Languages