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

相关推荐
SoaringHeart14 小时前
Flutter小技巧:IM音浪效果实现
前端·flutter
Bryce李小白1 天前
Flutter中实现页面跳转功能
flutter
RaidenLiu1 天前
Flutter 多环境配置:flavor
前端·flutter
忆江南1 天前
Widget 、 Element 和 RenderObject 关系
flutter
程序员老刘1 天前
“工信部要求9月30日前APP必须100%适配鸿蒙“ 是真的吗?
flutter·harmonyos
亿刀1 天前
WireGuard通讯原理
android·flutter
勤劳打代码2 天前
曲径通幽 —— Android 息屏 TCP 连接管理
android·tcp/ip·flutter
耳東陈2 天前
Flutter ScreenUtil Generator - 自动添加ScreenUtil后缀
flutter
恋猫de小郭2 天前
Flutter 里的 Layer 解析,带你了解不一样角度下的 Flutter 渲染逻辑
android·前端·flutter
愿天深海2 天前
Flutter 生命周期介绍
flutter