Copying and Pasting with Clipboard in Flutter
Copying
import 'package:flutter/services.dart';
Clipboard.setData(ClipboardData(text: 'Text to be copied'));
Pasting
This is more about retrieving the data from the clipboard rather than pasting.
import 'package:flutter/services.dart';
final textData = await Clipboard.getData(Clipboard.kTextPlain);
The argument for the getData
method is the media type format. By the way, the definition of Clipboard.kTextPlain
used in the example above is as follows:
static const String kTextPlain = 'text/plain';
Therefore, in the above example, data in text format is retrieved.
When you want to get an image, you might want to put something like image/png
(untested).
[Addendum]
Looking at the documentation for the ClipboardData
class, which represents the data stored in the Clipboard, I found the following description:
The system clipboard can contain data of various media types. This data structure currently supports only plain text data, in the text property.
As of now (April 10, 2022), it seems to support only text
data.
[End of Addendum]