Flutter无法从剪贴板读取 [英] Flutter can't read from Clipboard

查看:711
本文介绍了Flutter无法从剪贴板读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来问一个关于Flutter和Future and await机制的相当具体的问题,该问题似乎正在起作用,但是即使按照Google关于实现的建议,我的剪贴板在使用可编辑的文本字段时也无法真正起作用...

I come asking for quite a specific question regarding Flutter and the Future and await mechanism, which seems to be working, but my Clipboard does not really function while operating with my editable text fields, even following Google's advice on implementation...

这是我粘贴的代码:

onPressed: () async {
  await getMyData('text');
  _encodingController.text = clipData;
  Scaffold.of(context).showSnackBar(
    new SnackBar(
      content: new Text(
        "Pasted from Clipboard"),
      ),
    );
},

我的粘贴功能不起作用...在调试此以下功能的结果为null时,wth ?????????

what doesnt work is my paste functionality... While debugging the result of this following function is null, wth?????????

static Future<ClipboardData> getMyData(String format) async {
    final Map<String, dynamic> result =
        await SystemChannels.platform.invokeMethod(
      'Clipboard.getData',
      format,
    );

    if (result == null) {
      return null;
    } else {
      clipData = ClipboardData(text: result['text']).text;
      return ClipboardData(text: result['text'].text);
    }
  }

我可能正在使用期货,并且异步等待错误,希望您能提供一些指导!!!正在使用剪贴板管理器插件进行复制!非常感谢!

I am probably using the Futures and async await wrong, would love some guidance!!! Copying is working using the Clipboard Manager plugin! Thanks very much!

推荐答案

您可以简单地将Flutter的现有库代码从剪贴板重新用于getData.

You can simply re-use Flutter's existing library code to getData from Clipboard.

ClipboardData data = await Clipboard.getData('text/plain');

这篇关于Flutter无法从剪贴板读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆