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

相关推荐
孤鸿玉5 小时前
Fluter InteractiveViewer 与ScrollView滑动冲突问题解决
flutter
叽哥11 小时前
Flutter Riverpod上手指南
android·flutter·ios
BG1 天前
Flutter 简仿Excel表格组件介绍
flutter
zhangmeng1 天前
FlutterBoost在iOS26真机运行崩溃问题
flutter·app·swift
恋猫de小郭1 天前
对于普通程序员来说 AI 是什么?AI 究竟用的是什么?
前端·flutter·ai编程
卡尔特斯1 天前
Flutter A GlobalKey was used multipletimes inside one widget'schild list.The ...
flutter
w_y_fan1 天前
Flutter 滚动组件总结
前端·flutter
醉过才知酒浓1 天前
Flutter Getx 的页面传参
flutter
火柴就是我2 天前
flutter 之真手势冲突处理
android·flutter
Speed1232 天前
`mockito` 的核心“打桩”规则
flutter·dart