clipboardCopyableText static method
Widget
clipboardCopyableText(
- BuildContext context,
- String text, {
- void onCopied(
- String text
- TextStyle? style,
Creates a text widget with a copy-to-clipboard button.
Parameters:
context: The build context to access theme datatext: The text to display and copyonCopied: Optional callback invoked after text is copiedstyle: Optional text style. Defaults to caption style
Returns a Row containing the text and a copy button.
Implementation
static Widget clipboardCopyableText(BuildContext context, String text,
{void Function(String text)? onCopied, TextStyle? style}) {
style = style ?? captionStyle(context);
return Row(children: [
Text(text, style: style),
IconButton(
visualDensity: VisualDensity.compact,
onPressed: () {
Clipboard.setData(ClipboardData(text: text));
if (onCopied != null) {
onCopied(text);
}
},
icon: Icon(Icons.copy,
size: style.fontSize, color: Theme.of(context).primaryColor),
tooltip: 'Click to copy')
]);
}