flutter复制口令返回app监听粘贴板

dart 复制代码
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
        break;
      case AppLifecycleState.resumed: //从后台切换前台,界面可见
        handle();
        break;
      case AppLifecycleState.paused: // 界面不可见,后台
        break;
      case AppLifecycleState.detached: // APP结束时调用
        break;
    }
  }

以上代码会在app在初次启动以及app切换回来时触发handle()函数

dart 复制代码
handle() async {
    ClipboardData? clipboardData =
        await Clipboard.getData(Clipboard.kTextPlain); //获取粘贴板中的文本
    if (clipboardData != null) {
      if(clipboardData.text!.length>10
          &&clipboardData.text!.substring(0,9)=='粘贴板口令内容符合'){
        Future.delayed(const Duration(milliseconds: 200),(){
            Navigator.of(context).push(CustomRoute(const MyPage()));//跳转页面
        });
      }
    }
  }

切换App返回时监听粘贴板,如果口令符合要求,做出处理(如跳转页面或者启动弹框)

原文链接:https://blog.csdn.net/weixin_45003123/article/details/127234119

相关推荐
爱吃大芒果19 小时前
Flutter 主题与深色模式:全局样式统一与动态切换
开发语言·javascript·flutter·ecmascript·gitcode
小a杰.1 天前
Flutter 进阶:构建高性能跨平台应用的实践与技巧
flutter
巴拉巴拉~~1 天前
Flutter 通用轮播图组件 BannerWidget:自动播放 + 指示器 + 全场景适配
windows·flutter·microsoft
ujainu小1 天前
Flutter 结合 shared_preferences 2.5.4 实现本地轻量级数据存储
flutter
走在路上的菜鸟1 天前
Android学Dart学习笔记第十六节 类-构造方法
android·笔记·学习·flutter
hh.h.1 天前
Flutter适配鸿蒙轻量设备的资源节流方案
flutter·华为·harmonyos
巴拉巴拉~~1 天前
Flutter 通用下拉刷新上拉加载列表 RefreshListWidget:分页 + 空态 + 错误处理
flutter
走在路上的菜鸟1 天前
Android学Dart学习笔记第十七节 类-成员方法
android·笔记·学习·flutter
走在路上的菜鸟1 天前
Android学Dart学习笔记第十八节 类-继承
android·笔记·学习·flutter
巴拉巴拉~~1 天前
Flutter 通用列表刷新加载组件 CommonRefreshList:下拉刷新 + 上拉加载 + 状态适配
前端·javascript·flutter