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

相关推荐
恋猫de小郭10 小时前
Flutter THLC 的 WebView 滚动终于从 70 FPS 提升到 120 FPS
android·前端·flutter
好的佩奇21 小时前
Dart 之扩展类型
android·flutter·dart
恋猫de小郭1 天前
Flutter 下 AOT 一个你怎么都想不出来的 Bug ,JIT 正常的计算,在 AOT 居然算错了
android·前端·flutter
好的佩奇2 天前
Dart 之扩展方法
android·flutter·dart
好的佩奇2 天前
蓝牙之经典蓝牙
android·flutter·蓝牙
传奇开心果编程2 天前
【Flutter踩坑排雷】第19课:路由硬编码坑|字符串路由书写错误,页面跳转失败排查
android·flutter·ios·移动开发·跨平台·ui框架·声明式ui
Nerd(BUG版)3 天前
Flutter学习day5--事件手势与命中测试
学习·flutter
传奇开心果3 天前
【Flutter踩坑排雷】第5课:扩展方法冲突坑|同名扩展引发编译歧义,故障规避手段
android·flutter
雪铃儿4 天前
Flutter 双端热更新新方案:基于 Dart 官方动态模块的 flutter_patcher 1.0.0
flutter·hotfix