formatMap method

String formatMap(
  1. Map<String, Object> args
)

Formats this string using named placeholders {key}.

'Hello {name}!'.formatMap({'name': 'World'}) // 'Hello World!'

Implementation

String formatMap(Map<String, Object> args) {
  return replaceAllMapped(RegExp(r'\{(\w+)\}'), (m) {
    final key = m.group(1)!;
    if (!args.containsKey(key)) throw ArgumentError('Key "$key" not found');
    return args[key]!.toString();
  });
}