win32_clipboard 2.0.2 copy "win32_clipboard: ^2.0.2" to clipboard
win32_clipboard: ^2.0.2 copied to clipboard

A modern, type-safe Dart API for accessing and managing the Windows Clipboard.

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

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.

13
likes
160
points
585
downloads

Publisher

verified publisherhalildurmus.dev

Weekly Downloads

A modern, type-safe Dart API for accessing and managing the Windows Clipboard.

Repository (GitHub)
View/report issues
Contributing

Topics

#clipboard #win32 #ffi #windows

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

BSD-3-Clause (license)

Dependencies

ffi, ffi_leak_tracker, meta, win32

More

Packages that depend on win32_clipboard