fillTemplate function

String fillTemplate(
  1. String template,
  2. Map<String, String> values
)

Fills {key} placeholders from values; unknown placeholders are left as they are rather than throwing, so a typo in a translation shows up on screen instead of crashing the dialog.

Implementation

String fillTemplate(String template, Map<String, String> values) =>
    template.replaceAllMapped(RegExp(r'\{(\w+)\}'), (m) {
      return values[m.group(1)] ?? m.group(0)!;
    });