Reputation: 67
Please, I added a picture below. Here is a container I've created with a button, with an icon and two different texts(one up and one down). Please how do I do it that if I long press on the button the bottom text will be copied to my clipboard, so I can paste it elsewhere on my phone
Upvotes: 0
Views: 1669
Reputation: 428
Import this:
import 'package:flutter/services.dart';
Wrap your button widget with GestureDetector
and add an anonymous function
GestureDetector(
onLongPress: () {
Clipboard.setData(ClipboardData(text: yourText));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Text copied to clipboard"),
),
);
},
child: // Your button widget
)
Edit: I've added code to show a popup that says text copied to clipboard.
Upvotes: 1
Reputation: 21
import 'package:flutter/services.dart';
Put your container widget inside the GestureDectector
and onLongPress
you can add function to copy your desired text to clipboard.
GestureDetector(
onLongPress: () {
Clipboard.setData(ClipboardData(text: yourText));
Toast.show('Text Copied');
},
child: // Your Container
)
Upvotes: 0