flutter_paste_input library
A Flutter plugin for intercepting paste events in text fields.
This plugin enables your app to detect when users paste content (text or images) into a TextField, TextFormField, or similar widgets.
Getting Started
Wrap your text input with PasteWrapper:
import 'package:flutter_paste_input/flutter_paste_input.dart';
PasteWrapper(
onPaste: (payload) {
switch (payload) {
case TextPaste(:final text):
print('Pasted text: $text');
case ImagePaste(:final uris):
print('Pasted ${uris.length} images');
// Handle images - uris are temporary file paths
case UnsupportedPaste():
print('Unsupported content');
}
},
child: TextField(
decoration: InputDecoration(hintText: 'Type or paste here...'),
),
)
Platform Support
| Platform | Support |
|---|---|
| iOS | ✅ |
| Android | ✅ |
| macOS | ✅ |
| Linux | ✅ |
| Windows | ✅ |
Image Handling
When images are pasted, they are saved as temporary files in the app's cache directory. The ImagePaste.uris field contains the file paths. If you need to persist these images, copy them to a permanent location.
To clean up temporary files, call:
await PasteChannel.instance.clearTempFiles();
Classes
- ClipboardContent
- Represents the complete clipboard content.
- ClipboardItem
- Represents a single item from the clipboard.
- ImagePaste
- Represents pasted image content.
- PasteChannel
- Handles communication with the native platform for paste events.
- PastePayload
- Represents the content pasted by the user.
- PasteWrapper
- A widget that wraps a TextField or TextFormField to intercept paste events.
- RawClipboardItem
- Represents a raw clipboard item with binary data.
- RawImagePaste
- Represents pasted image content with raw data.
- TextPaste
- Represents pasted text content.
- UnsupportedPaste
- Represents unsupported paste content.
Enums
- PasteType
- Types of paste content that can be filtered.