简体   繁体   English

Flutter - 如何将按钮添加到在文本字段中粘贴所选文本?

[英]Flutter - how can I add the button to Paste selected text in textfield?

I want to implement button, by clicking that button I want to paste the select text (From any source Exp - from the message app) into the textfield.我想实现按钮,通过单击该按钮,我想将选择的文本(来自任何来源 Exp - 来自消息应用程序)粘贴到文本字段中。 We have a plugin for make a button to copy the text, do we have anything similar to paste the text.我们有一个用于制作按钮来复制文本的插件,我们有什么类似的东西可以粘贴文本。

If the text you want to select is from the same app, you can achieve this using Clipboard如果您要选择的文本来自同一个应用程序,您可以使用剪贴板来实现

TextEditingController textFieldController = new TextEditingController();
Clipboard.setData(new ClipboardData(text: "copied text")); // copy text

onPressed() async { // onPress function of button
  ClipboardData data = await Clipboard.getData('text/plain');
  setState(() {
    textFieldController.text = data.text.toString(); // this will paste "copied text" to textFieldController
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM