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}');
            }
          }
        }
      });
    }

猜你喜欢

转载自blog.csdn.net/weixin_44911775/article/details/133375979