interpolateVariables function
Replaces {{ name }} placeholders in text using variables. A matched
value is stringified via toString(); an unmatched placeholder collapses to
an empty string; a null/empty variables map or a string with no {{
returns text unchanged.
Implementation
String interpolateVariables(String text, Map<String, dynamic>? variables) {
if (variables == null || variables.isEmpty || !text.contains('{{')) {
return text;
}
return text.replaceAllMapped(
_identifierPlaceholderPattern,
(m) => variables[m.group(1)]?.toString() ?? '',
);
}