美文网首页
Flutter-webview-中文参数

Flutter-webview-中文参数

作者: 间歇性丶神经病患者 | 来源:发表于2021-04-19 16:41 被阅读0次
    ///?userCode=xxx&avatarUrl=xxx&nickName=xxx
    Future<String> _formatUrl(String oldUrl) async {
      if (oldUrl != null && oldUrl.isNotEmpty == true) {
        String _userCode;
        String _avatarUrl;
        String _nickName;
        UserInfoModel _user = await UserManager.getUserInfo();
        if (_user != null) {
          _userCode = _user?.resultData?.organization?.organizationId?.toString();
          _nickName = _user?.resultData?.organization?.organizationName;
          String _userHead = _user?.resultData?.user?.portraitUrl ?? "";
          if (_userHead.contains('https://wx.qlogo.cn/')) {
            _avatarUrl = _userHead;
          } else {
            _avatarUrl = ImgSize.getImgUrlBySize(_userHead);
          }
          String _suffix;
          if (oldUrl.contains("?")) {
            _suffix =
                '&userCode=$_userCode&avatarUrl=$_avatarUrl&nickName=${Uri.encodeComponent(_nickName)}';
          } else {
            _suffix =
                '?userCode=$_userCode&avatarUrl=$_avatarUrl&nickName=${Uri.encodeComponent(_nickName)}';
          }
          return '$oldUrl$_suffix';
        } else {
          return oldUrl;
        }
      } else {
        return oldUrl;
      }
    }
    

    中文需要用Uri.encodeComponent转码

    相关文章

      网友评论

          本文标题:Flutter-webview-中文参数

          本文链接:https://www.haomeiwen.com/subject/qsailltx.html