首页 > 其他分享 >flutter 复制文本功能文件

flutter 复制文本功能文件

时间:2023-09-21 16:57:47浏览次数:28  
标签:format text clipboard Clipboard result 复制 文本 data flutter

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


import 'package:flutter/foundation.dart';

import 'system_channels.dart';

/// Data stored on the system clipboard.
///
/// The system clipboard can contain data of various media types. This data
/// structure currently supports only plain text data, in the [text] property.
@immutable
class ClipboardData {
  /// Creates data for the system clipboard.
  const ClipboardData({ this.text });

  /// Plain text variant of this clipboard data.
  final String? text;
}

/// Utility methods for interacting with the system's clipboard.
class Clipboard {
  // This class is not meant to be instantiated or extended; this constructor
  // prevents instantiation and extension.
  Clipboard._();

  // Constants for common [getData] [format] types.

  /// Plain text data format string.
  ///
  /// Used with [getData].
  static const String kTextPlain = 'text/plain';

  /// Stores the given clipboard data on the clipboard.
  static Future<void> setData(ClipboardData data) async {
    await SystemChannels.platform.invokeMethod<void>(
      'Clipboard.setData',
      <String, dynamic>{
        'text': data.text,
      },
    );
  }

  /// Retrieves data from the clipboard that matches the given format.
  ///
  /// The `format` argument specifies the media type, such as `text/plain`, of
  /// the data to obtain.
  ///
  /// Returns a future which completes to null if the data could not be
  /// obtained, and to a [ClipboardData] object if it could.
  static Future<ClipboardData?> getData(String format) async {
    final Map<String, dynamic>? result = await SystemChannels.platform.invokeMethod(
      'Clipboard.getData',
      format,
    );
    if (result == null) {
      return null;
    }
    return ClipboardData(text: result['text'] as String?);
  }

  /// Returns a future that resolves to true iff the clipboard contains string
  /// data.
  ///
  /// See also:
  ///   * [The iOS hasStrings method](https://developer.apple.com/documentation/uikit/uipasteboard/1829416-hasstrings?language=objc).
  static Future<bool> hasStrings() async {
    final Map<String, dynamic>? result = await SystemChannels.platform.invokeMethod(
      'Clipboard.hasStrings',
      Clipboard.kTextPlain,
    );
    if (result == null) {
      return false;
    }
    return result['value'] as bool;
  }
}

使用范例

Clipboard.setData(

    ClipboardData(text: audience.value.id))
.then((value) =>
showToast(
'home.successful_replication'
.tr)),

标签:format,text,clipboard,Clipboard,result,复制,文本,data,flutter
From: https://www.cnblogs.com/liangqilin/p/17720353.html

相关文章

  • Linux持续学习者的必备工具:文本处理神器awk
    Linux持续学习者的必备工具:文本处理神器awk原创 运维家 运维家 2023-09-0215:09 发表于北京收录于合集#awk1个#linux52个引言作为一名Linux持续学习者,我们经常需要处理各种各样的文本文件,例如日志文件、配置文件等。而对于大规模的文本数据,手动处理往往效率......
  • 行业分享:文本数据标注的整体流程、类型与应用场景
    上次分享的文本标注收到朋友们的咨询和讨论,那今天和大家分享一些文本数据标注行业情况。自然语言对话是网络大数据语义理解的主要挑战之一,被誉为人工智能皇冠上的宝石,而文本数据标注就是这一系列工作中最基础、最重要的环节。自然语言对话系统的研究是希望机器人能够理解人类的自然......
  • NET6/Framework 封装邮件发送纯文本/HTML/HTML+图片/附件
    NugetRuntime:Net6MailKit4.2.0MimeKit4.2.0发送纯文本{varbodyBuilder=newBodyBuilder();bodyBuilder.TextBody="这是一封纯文本邮件";message.Body=bodyBuilder.ToMessageBody();}{vartextPart=newTextPart("plain")......
  • java通过jdbc复制表数据实现备份
    importorg.apache.commons.lang3.StringUtils;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;importjava.sql.*;@Servicepublicclass......
  • 文本数据预处理(二)用于大预言模型训练
    收集好的txt数据要先过滤一下,删掉无效信息。然后再按下面步骤处理classDataPreprocessor():'''def__init__(self,vocab_file,longest_sentence):self.tok=BertTokenizer(vocab_file)self.longest_sentence=longest_sentenceself.end_sy......
  • [注意事项]复制出错,BeanUtils.copyProperties(c,question);
    问题定位:BeanUtils.copyProperties(c,question);是浅拷贝什么是浅拷贝:只是对主对象,第一层进行拷贝,对于对象中的对象,只是将其对象的引用复制一份,所以对副本对象的改变会影响到主对象。什么是深拷贝:将主对象的所有全部给副对象一份,复制完之后,就完全隔开,互相不影响。浅拷贝,栈......
  • Python用于解析和修改文本数据-pyparsing模块教程
    Python库解析地址PyParsing人们普遍认为,Python编程语言的pyparsing模块是对文本数据进行操作的一个宝贵工具。用于解析和修改文本数据的pyparsing包,简化了对地址的操作。这是因为该模块可以转换和帮助解析地址。在这篇文章中,我们将讨论PyParsing模块在处理解析以及修改时的......
  • Flutter开发桌面应用的一些探索
    引言在移动应用开发领域,Flutter已经赢得了广泛的认可和采用,成为了跨平台移动应用开发的瑞士军刀。然而,Flutter的魅力并不仅限于移动平台,它还可以用于开发桌面应用程序,为开发人员提供了一种全新的选择。本文将深入探讨Flutter在桌面应用开发中的应用,以及目前国内新颖的跨端开发技......
  • Flutter 开发桌面应用有哪些优势?
    在移动应用开发领域,Flutter已经赢得了广泛的认可和采用,成为了跨平台移动应用开发的瑞士军刀。然而,Flutter的魅力并不仅限于移动平台,它还可以用于开发桌面应用程序,为开发人员提供了一种全新的选择。本文将深入探讨Flutter在桌面应用开发中的应用,以及目前国内新颖的跨端开发技术。桌......
  • el-table中自定义悬浮提示结构,添加复制功能
    效果展示:代码:代码copyText(text){navigator.clipboard.writeText(text).then(()=>{this.$message.success("文本复制成功");}).catch(()=>{this.$message.error("文本复制失败");......