Flutter state hook that provides functionality to copy text to the clipboard.
dependencies:
flutter_use: class Sample extends HookWidget {
@override
Widget build(BuildContext context) {
final copyToClipboard = useCopyToClipboard();
return Column(
children: [
if (copyToClipboard.copied != null)
Text("Copied: ${copyToClipboard.copied}"),
if (copyToClipboard.error != null)
Text("Error: ${copyToClipboard.error}"),
ElevatedButton(
onPressed: () {
copyToClipboard.copy("Hello, World!");
},
child: const Text('Copy Text'),
),
ElevatedButton(
onPressed: () {
copyToClipboard.copy("flutter_use is awesome!");
},
child: const Text('Copy Another Text'),
),
]
);
}
}copied: String?- the last successfully copied text;error: Object?- error occurred during copying, if any;copy(String)- copies the given text to clipboard;