How to use clipboard in Flutter

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

Install all of libraries below in pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  clipboard_manager: ^0.0.4
  clipboard: ^0.1.2+8

Table of Contents

clipboard_manager

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

It is quite simple to save a string to clipboard.

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

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

clipboard

clipboard is a flutter package that helps copy text to clipboard and paste from 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 clipboard

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

Leave a Comment

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

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