Async and Practical
String Template Lite
A tiny template renderer walks a {key: value} map and swaps each <<key>> placeholder in the template with the matching value. replaceAll does the heavy lifting; the loop just rebinds result once per entry.
Program
Play the program to render a small template with two placeholders.
string_template_lite.dart
void main() {
var template = '<<name>> has <<count>> tasks';
var values = {'name': 'Ada', 'count': '3'};
var result = template;
for (var entry in values.entries) {
result = result.replaceAll('<<${entry.key}>>', entry.value);
}
print(result);
}
placeholders
Wrap each key in `<<...>>` so the template reads cleanly next to surrounding text.
replaceAll
`result.replaceAll('<<name>>', 'Ada')` swaps every occurrence; safe when a placeholder repeats.
rebind
`result = result.replaceAll(...)` rebinds the same name each iteration since Dart strings are immutable.