Skip to content

Latest commit

 

History

History
50 lines (41 loc) · 1.24 KB

useCopyToClipboard.md

File metadata and controls

50 lines (41 loc) · 1.24 KB

useCopyToClipboard

Flutter state hook that provides functionality to copy text to the clipboard.

Installation

dependencies:
  flutter_use: 

Usage

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'),
        ),
      ]
    );
  }
}

Reference

  • copied: String? - the last successfully copied text;
  • error: Object? - error occurred during copying, if any;
  • copy(String) - copies the given text to clipboard;