-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3878 from canonical/gui-click-to-copy
use CopyableText (click-to-copy) in GUI for instance info
- Loading branch information
Showing
5 changed files
with
58 additions
and
17 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,46 @@ | ||
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> { | ||
var _copied = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
Widget text = Text( | ||
widget.text, | ||
style: widget.style, | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis, | ||
); | ||
|
||
// if there is no value, display "-" | ||
if (widget.text == '-') return text; | ||
|
||
return MouseRegion( | ||
cursor: SystemMouseCursors.click, | ||
onExit: (_) => setState(() => _copied = false), | ||
child: GestureDetector( | ||
onTap: () async { | ||
await Clipboard.setData(ClipboardData(text: widget.text)); | ||
setState(() => _copied = true); | ||
}, | ||
child: Tooltip( | ||
message: _copied ? 'Copied' : 'Click to copy', | ||
child: text, | ||
), | ||
), | ||
); | ||
} | ||
} |
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
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