clipboard_watcher

March 23, 2025 · View on GitHub

🚀 快速发布您的应用: 试试 Fastforge - 构建、打包和分发您的 Flutter 应用最简单的方式。

clipboard_watcher

pub version All Contributors

这个插件允许 Flutter 应用程序观察剪贴板的变化。


English | 简体中文


平台支持

平台支持
Linux✔️ 完全支持
macOS✔️ 完全支持
Windows✔️ 完全支持
iOS14+ 需要用户权限才能读取从其他应用复制的数据
旧版本完全支持开箱即用
Android10+ 仅当应用程序位于前台时有效
旧版本完全支持开箱即用

快速开始

安装

将此添加到你的软件包的 pubspec.yaml 文件:

dependencies:
  clipboard_watcher: ^0.2.1

用法

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with ClipboardListener {
  @override
  void initState() {
    clipboardWatcher.addListener(this);
    // start watch
    clipboardWatcher.start();
    super.initState();
  }

  @override
  void dispose() {
    clipboardWatcher.removeListener(this);
    // stop watch
    clipboardWatcher.stop();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // ...
  }

  @override
  void onClipboardChanged() async {
    ClipboardData? newClipboardData = await Clipboard.getData(Clipboard.kTextPlain);
    print(newClipboardData?.text ?? "");
  }
}

请看这个插件的示例应用,以了解完整的例子。

谁在用使用它?

  • 比译 - 一个便捷的翻译和词典应用程序。

贡献者

LiJianying
LiJianying

💻
Ademar
Ademar

💻
Amritpal Singh
Amritpal Singh

💻
J-P Nurmi
J-P Nurmi

💻
Leo Peng
Leo Peng

💻
Add your contributions

许可证

MIT