How to Use Clipboard in Flutter

Copying data to the clipboard and pasting data from the clipboard is quite simple in Flutter. However, you still need to install the necessary plugin to access the clipboard.

super_clipboard

The super_clipboard package for Flutter provides comprehensive access to the clipboard, allowing users to read and write rich text, images, and other formats. It is platform agnostic and supports macOS, iOS, Android, Windows, Linux, and the Web. 

The package provides multiple representations for clipboard items, making it easy to work with different data types. It also allows developers to provide clipboard data on demand, which can improve performance and reduce memory usage.

rich_clipboard

This Flutter plugin enables users to access and manipulate rich text and other data types stored in the system clipboard. It provides functions to read and write to the clipboard, as well as the ability to detect when the content of the clipboard has changed.

This plugin can be used to copy and paste text, images, and other data between applications. It can be used to store data for later use and to provide a more efficient way of transferring data between systems.

import 'package:rich_clipboard/rich_clipboard.dart';
...
final clipboardData = await RichClipboard.getData();
if (clipboardData.html != null) {
  // Do something with HTML
} else if (clipboardData.text != null) {
  // Do something with plain text
}
...

final plainText = 'Hello there';
final html = '<html><body><h1>$plainText</h1></body></html>';
await RichClipboard.setData(RichClipboardData({
  text: plainText,
  html: html,
}));

clipboard_manager

This plugin allows developers to copy text to the clipboard in both Android and iOS.

It is quite simple to save a string to the clipboard.

ClipboardManager.copyToClipBoard("some text").then((result) { print('yay, text was copied'); });

ClipboardManager.copyToClipBoard("any text").then((result) {
                        final snackBar = SnackBar(
                          content: Text('Copied to Clipboard'),
                          action: SnackBarAction(
                            label: 'Undo',
                            onPressed: () {},
                          ),
                        );
                        Scaffold.of(context).showSnackBar(snackBar);
                      });

The con of this library is that it doesn’t support pasting from the clipboard’s latest entry.

clipboard

clipboard is a flutter package that helps copy text to paste it from the clipboard.

Copy to clipboard

 FlutterClipboard.copy('This is an important text. I must save it to share.').then(( value ) => print('text was copied!'));

Paste the last entry in the clipboard:

FlutterClipboard.paste().then((value) {
	print(value);
	setState(() {});
});

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close