1

After copying the text of the SelectableText widget, I want to display a toast message. But I don't see an option to do that. What should I do?

Queen Ellery
  • 481
  • 1
  • 6
  • 11

2 Answers2

0

following works for me, shows a toast message after copying data to device clipboard:

 Clipboard.setData(ClipboardData(
              text: global_variables.myQRpartnerToStayInTouchWithUid))
          .then(
              (_) => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
                      content: Text(
                    'Copied to clipboard',
                    textAlign: TextAlign.right,
                  ))));

my code based on answer at https://stackoverflow.com/a/68321291/3120387

tmr
  • 1,500
  • 15
  • 22
-1
            Clipboard.setData(ClipboardData(text: "message"))
                .then((_) {
              
 ScaffoldMessenger.of(context).showSnackBar(flutterToast("Copy,false"));
            });
        
// flutterToast is common widget like this
// packages fluttertoast latest version recommended

flutterToast(String massage, bool set) {
  Fluttertoast.showToast(
     msg: massage,
     toastLength: Toast.LENGTH_SHORT,
     gravity: set ? ToastGravity.TOP : ToastGravity.BOTTOM,
     timeInSecForIosWeb: 1,
     backgroundColor: set ? Colors.red : Colors.green,
     textColor: Colors.white,
     fontSize: 16.0);
}
make
  • 1