replaceByIterable static method
Replaces placeholders in the given path
using values from the params
iterable.
Example:
Iterable<String> params = ['value1', 'value2'];
String result = PathReplacer.replaceByIterable('/path/{param1}/endpoint/{param2}', params);
// Result: '/path/value1/endpoint/value2'
Implementation
static String replaceByIterable(String path, Iterable<String> params) {
int i = 0;
return path.replaceAllMapped(RegExp(r'{(\w+)}'), (match) {
return i < params.length ? params.elementAt(i++) : match.group(0)!;
});
}