You can use this library clipboard_manager to do the actual act of storing the text in the clipboard. Then just access the text you want to copy through the TextEditingController
instance.
RaisedButton(
child: Text('Copy'),
onPressed: () {
ClipboardManager.copyToClipBoard(
_textEditingController.value.text)
.then((result) {
final snackBar = SnackBar(
content: Text('Copied to Clipboard'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {},
),
);
Scaffold.of(context).showSnackBar(snackBar);
});
},
),
or access the String
through a variable
RaisedButton(
child: Text('Copy'),
onPressed: () {
ClipboardManager.copyToClipBoard(
_variableContainingString)
.then((result) {
final snackBar = SnackBar(
content: Text('Copied to Clipboard'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {},
),
);
Scaffold.of(context).showSnackBar(snackBar);
});
},
),