flutter 递归

 if (!Global.wsImMessageQueueState) {
      Global.wsImMessageQueueState = true;
      startProcessingMessageQueue(true);//开始执行
    }

  startProcessingMessageQueue(bool isExistMessage) {
    if (isExistMessage) {
      if (Global.wsImMessageQueue.isNotEmpty) {
        PrintUtil.prints(
            'WsIm消息队列处理 === > 开始处理 ${Global.wsImMessageQueue[0].recvChatMsg?.serverMsgId}');
        if (Global.wsImMessageQueue[0].recvChatMsg != null) {
          WsImDBUtil().insertMessage(Global.wsImMessageQueue[0].recvChatMsg!,
              Global.wsImMessageQueue[0].isOffLineMessage);

          Global.wsImMessageQueue.remove(Global.wsImMessageQueue[0]);
          PrintUtil.prints('WsIm消息队列处理 === > 处理完成 移除消息');
          Future.delayed(const Duration(milliseconds: 100), () {
            startProcessingMessageQueue(Global.wsImMessageQueue.isNotEmpty);//递归,一直调用
          });
        }
      }
    } else {
      PrintUtil.prints('WsIm消息队列处理 === > 消息处理完成');
      Global.wsImMessageQueueState = false;//直到执行到false为止
    }
  }

我自己写的

verifyGetBaseInfo(switchExtra);//开始执行


    verifyGetBaseInfo(SwitchExtra? switchExtra) {
      int numb = 0;
      //获取扩展信息
      UserInfoUtil().getBaseUserInfo();
      if (_verifyTimer != null) {
        print('资料验证-之前不为null,取消计时器');
        _verifyTimer?.cancel();
      }
      //每一秒就都检查是否有拿到性别,主播信息,公会信息(不用定时器的吧)
      _verifyTimer = Timer.periodic(Duration(milliseconds: 1000), (timer) {
        print('资料验证-进入倒计时');
        numb = numb + 1;
        if (numb >= 10) {
          _verifyTimer?.cancel();
          print('资料验证-10次后取消倒计时');
        }
        print(
            '资料验证-gender:${Global.myUserInfo?.gender} chat_is_auth:${Global.myUserInfo?.userExpandInfo?.chat_is_auth} union_identity:${Global.myUserInfo?.userExpandInfo?.union_identity}');
        if (Global.myUserInfo?.gender == null ||
            Global.myUserInfo?.userExpandInfo?.chat_is_auth == null ||
            Global.myUserInfo?.userExpandInfo?.union_identity == null) {
            //拿不到数据进入递归
          verifyGetBaseInfo(switchExtra);
          print('资料验证-进入迭代');
        }
        if (Global.myUserInfo?.gender != null &&
            Global.myUserInfo?.userExpandInfo?.chat_is_auth != null &&
            Global.myUserInfo?.userExpandInfo?.union_identity != null) {
            //拿到数据后取消定时器,开始判断
          if (_verifyTimer != null) {
            _verifyTimer?.cancel();
          }
          if (switchExtra != null) {
            if (switchExtra.sex == '1') {
              //资料验证
              Global.verifyInformationSwitch = true;
              PrintUtil.prints('资料验证-全部生效${Global.verifyInformationSwitch}');
            } else if (switchExtra.sex == '2') {
              if (Global.myUserInfo?.gender == 1) {
                //只男用户生效
                Global.verifyInformationSwitch = true;
                if (Global.myUserInfo?.userExpandInfo?.chat_is_auth == 1 ||
                    Global.myUserInfo?.userExpandInfo?.union_identity == 1) {
                  Global.verifyInformationSwitch = false;
                }
                PrintUtil.prints('资料验证-男用户生效${Global.verifyInformationSwitch}');
              }
            } else if (switchExtra.sex == '3') {
              if (Global.myUserInfo?.gender == 2) {
                //只女用户生效
                Global.verifyInformationSwitch = true;
                if (Global.myUserInfo?.userExpandInfo?.chat_is_auth == 1 ||
                    Global.myUserInfo?.userExpandInfo?.union_identity == 1) {
                  Global.verifyInformationSwitch = false;
                }
                PrintUtil.prints('资料验证-女用户生效${Global.verifyInformationSwitch}');
              }
            } else if (switchExtra.sex == '4') {
              //男女用户生效
              Global.verifyInformationSwitch = true;
              if (Global.myUserInfo?.userExpandInfo?.chat_is_auth == 1 ||
                  Global.myUserInfo?.userExpandInfo?.union_identity == 1) {
                Global.verifyInformationSwitch = false;
              }
              PrintUtil.prints('资料验证-男女用户生效${Global.verifyInformationSwitch}');
            }
          }
        }
      });
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值