-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement click-to-copy in vm_table_headers
- Loading branch information
Showing
4 changed files
with
68 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/material.dart' hide Tooltip; | ||
import 'package:flutter/services.dart'; | ||
import 'tooltip.dart'; | ||
|
||
class CopyableText extends StatefulWidget { | ||
final String text; | ||
final TextStyle? style; | ||
|
||
const CopyableText(this.text, {super.key, this.style}); | ||
|
||
@override | ||
State<CopyableText> createState() => _CopyableTextState(); | ||
} | ||
|
||
class _CopyableTextState extends State<CopyableText> { | ||
bool _copied = false; | ||
|
||
void _copyToClipboard() async { | ||
await Clipboard.setData(ClipboardData(text: widget.text)); | ||
setState(() => _copied = true); | ||
} | ||
|
||
void _resetCopied() { | ||
if (_copied) { | ||
setState(() => _copied = false); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MouseRegion( | ||
cursor: SystemMouseCursors.click, | ||
onExit: (_) => _resetCopied(), | ||
child: GestureDetector( | ||
onTap: _copyToClipboard, | ||
child: Tooltip( | ||
message: _copied ? 'Copied' : 'Click to copy', | ||
child: Text( | ||
widget.text, | ||
style: widget.style, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters