11import  'package:flutter/material.dart'  hide  Tooltip;
22import  'package:flutter/services.dart' ;
3+ 
34import  'tooltip.dart' ;
45
56class  CopyableText  extends  StatefulWidget  {
@@ -13,20 +14,7 @@ class CopyableText extends StatefulWidget {
1314}
1415
1516class  _CopyableTextState  extends  State <CopyableText > {
16-   bool  _copied =  false ;
17-   bool  get  _isCopyable =>  widget.text !=  '-' ;
18- 
19-   void  _copyToClipboard () async  {
20-     if  (! _isCopyable) return ;
21-     await  Clipboard .setData (ClipboardData (text:  widget.text));
22-     setState (() =>  _copied =  true );
23-   }
24- 
25-   void  _resetCopied () {
26-     if  (_copied) {
27-       setState (() =>  _copied =  false );
28-     }
29-   }
17+   var  _copied =  false ;
3018
3119  @override 
3220  Widget  build (BuildContext  context) {
@@ -37,13 +25,17 @@ class _CopyableTextState extends State<CopyableText> {
3725      overflow:  TextOverflow .ellipsis,
3826    );
3927
40-     if  (! _isCopyable) return  text;
28+     // if there is no value, display "-" 
29+     if  (widget.text ==  '-' ) return  text;
4130
4231    return  MouseRegion (
4332      cursor:  SystemMouseCursors .click,
44-       onExit:  (_) =>  _resetCopied ( ),
33+       onExit:  (_) =>  setState (()  =>  _copied  =   false ),
4534      child:  GestureDetector (
46-         onTap:  _copyToClipboard,
35+         onTap:  () async  {
36+           await  Clipboard .setData (ClipboardData (text:  widget.text));
37+           setState (() =>  _copied =  true );
38+         },
4739        child:  Tooltip (
4840          message:  _copied ?  'Copied'  :  'Click to copy' ,
4941          child:  text,
0 commit comments