expandPath static method
Expends the path by populating it's dynamic-segments with
their corresponding values from params
e.g if template
= '/products/:id' and params
= {'id':'5'}
the result is '/products/5'
Implementation
static String expandPath(String template, Map<String, dynamic> params) {
if (mapNullOrEmpty(params)) {
return template;
}
var paramsRegex = RegExp(":(${params.keys.join('|')})");
var path = template.replaceAllMapped(paramsRegex, (match) {
return params[match.group(1)]?.toString() ?? '';
});
return path;
}