toMergeUrl method
url参数合并(referenceUrl参数向targetUrl合并)
targetUrl
合并参数后的url连接
Implementation
String toMergeUrl({String targetUrl = ""}) {
if ([targetUrl, this].hasEmptyElement) {
return targetUrl;
}
var targetUri = Uri.parse(targetUrl);
var refUri = Uri.parse(this);
var parameters = refUri.queryParameters;
if (parameters.isEmptyMap()) {
return targetUrl;
}
//原uri->map不能修改
Map<String, dynamic> paramsMap = {};
paramsMap.addAll(targetUri.queryParameters);
parameters.forEach((String key, dynamic value) {
if (!paramsMap.containsKey(key)) {
paramsMap[key] = value;
}
});
var replace = targetUri.replace(queryParameters: paramsMap);
return replace.toString();
}