String interpolation in Dart
Templates with $, expression braces, and multiline literals.
void main() {
const bird = 'goldfinch';
const count = 7;
// $name splices a value; ${...} splices any expression.
print('$count $bird sightings');
print('Even flock? ${count.isEven}');
// Adjacent literals concatenate; triple quotes span lines.
const banner = 'MORNING '
'WATCH';
const sign = '''
Hide rules:
quiet voices, $bird nesting''';
print('$banner\n$sign');
}
How it works
$countdrops a value in;${count.isEven}runs any expression.- Adjacent string literals concatenate across lines.
- Triple quotes span lines and still interpolate.
Keywords and builtins used here
constvoid
The run, in numbers
- Lines
- 15
- Characters to type
- 368
- Tokens
- 75
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 64 seconds.
Step 3 of 3 in Values, step 3 of 27 in Language basics.