flutter 个人用户信息有多个接口拼接成的

2023-12-13 06:23:36

先获取个人信息

  ///获取个人信息
  getNearbyUserInfo(bool isGetExpandInfo) {
    PrintUtil.prints(
        '获取用户信息 getNearbyUserInfo ===> accessToken:${SPHelper.getAccessToken}');
    if (SPHelper.getAccessToken == '' || SPHelper.getAccessToken == null) {
      return;
    }

    HttpRequest.intance.postHttpFromBusiness(Api.GET_BASEINFO, (data) {
      PrintUtil.prints('用户信息 Global.appContext${Global.appContext}');
      if (data.isNotEmpty) {
        LoadingUtil.dismissLoading();
        MyUserInfo user = MyUserInfo.fromJson(data);
        if (user.gender == 1 || user.gender == 2) {
          //保存个人性别,1男2女
          saveSexList(user.gender ?? 1);
        }
        user.setUserIMID('${user.userID}');
        user.setConversationID("c2c_${user.userID}");

        Global.userId = user.userIMID ?? '';
        Global.userAvatar = user.faceUrlThumb ?? '';
        if (user.avatarStatus == 1) {
          Global.isUploadAvatar = true;
          Global.conversationUploadAvatar = false;
        } else {
          Global.isUploadAvatar = false;
        }

        CacheFileString().loadStringAsync(user.faceUrlThumb!);
        Provider.of<UserModel>(Global.appContext, listen: false).setInfo(user);

        if (isGetExpandInfo) {
          if (Global.myUserInfo?.userExpandInfo == null) {
            getUserExpandInfo(0);
          }
        }

        if (Global.myUserInfo?.countryIcon == null ||
            Global.myUserInfo?.countryName == null) {
          if (user.country != null) {
            if (user.country != '') {
              getCountryInfo(user.country ?? '');
            }
          }
        }
      }
    }, (error, errorCode) {
      LoadingUtil.dismissLoading();
    }, parameters: {'user_id': Global.userId});
  }

继续拼接扩展信息,先获取旧的,再拼接新的

  ///获取用户扩展信息
  getUserExpandInfo(int getType) {
    HttpRequest.intance.postHttpFromBusiness(Api.API_USER_EXTENDINFO, (data) {
      PrintUtil.prints('用户信息 获取用户扩展信息 ${data.toString()}');
      if (data.isNotEmpty) {
        UserExpandInfo userExpandInfo = UserExpandInfo.fromJson(data);
        PrintUtil.prints('用户信息 获取用户扩展信息 ${userExpandInfo.toJson()}');

        MyUserInfo? myUserInfo =
            Provider.of<UserModel>(Global.appContext, listen: false).info;//先获取旧的

        if (myUserInfo != null) {
          myUserInfo.userExpandInfo = userExpandInfo;//拼接新的
          Provider.of<UserModel>(Global.appContext, listen: false)
              .setInfo(myUserInfo);

          Provider.of<WalletProvider>(Global.navigatorKey.currentContext!,
                  listen: false)
              .updateWallet(
                  goldCoin: userExpandInfo.gold_coin,
                  diamond: userExpandInfo.diamond);

          EventBusUtil.fire(GetUserExtendInfoEvent(getType, true));
          EventBusUtil.fire(RefreshProfileEvent());
        }
      }
    }, (error, errorCode) {
      EventBusUtil.fire(GetUserExtendInfoEvent(getType, false));
    });
  }

文章来源:https://blog.csdn.net/weixin_44911775/article/details/134940765
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。