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

相关推荐
嵩风抚1 小时前
一款HK银行APP的业务+技术
android·flutter·react native·html5
不羁的木木4 小时前
给鸿蒙 App 增加广播收发能力 —— flutter_broadcasts 的鸿蒙使用指南
flutter·harmonyos
不羁的木木4 小时前
给鸿蒙 App 增加打开外部网页能力 —— flutter_web_browser 的鸿蒙使用指南
前端·flutter·harmonyos
安好说AI5 小时前
Flutter 三方库 sound_mode 的鸿蒙化适配指南:免权限读取与受限写入的契约对齐
flutter·harmonyos·鸿蒙
●VON5 小时前
Flutter 鸿蒙 disk_space_2 1.0.13 使用实战:下载前检查磁盘空间
flutter·华为·harmonyos·鸿蒙
●VON15 小时前
Flutter 鸿蒙插件适配实战:用 device_screen_brightness 2.0.0 控制并监听屏幕亮度
flutter·华为·harmonyos
风早爽太1 天前
Flutter 开发笔记:share_plus 分享插件
笔记·flutter
●VON1 天前
Flutter 鸿蒙插件适配实战:用 boot_time_plugin 1.0.0 读取启动时间与运行时长
flutter·华为·harmonyos
不羁的木木1 天前
给鸿蒙 App 增加唤起系统邮件发送能力 —— flutter_email_sender 的鸿蒙使用指南
flutter·华为·harmonyos
●VON1 天前
Flutter 鸿蒙插件适配实战:用 accurate_storage_info 0.1.1 查询总量、可用量与已用量
flutter·华为·harmonyos