Python String Interpolation, Multiline & Raw Strings
Strings in Dart are immutable sequences of UTF-16 code units. String interpolation allows seamless embedding of variables (`$name`) and complex expressions (`${cart.total * 1.08}`) directly inside string literals without ugly string concatenation. Dart also supports multiline strings (`"""..."""`) and raw strings (`r"\n"`).
"String interpolation is like a fill-in-the-blank template: the template sentence is clear, and the dynamic variables fill into the blanks automatically."
Deep Dive: How It Works
Simple Variable Interpolation: `$variable` evaluates and casts the variable to string.
Complex Expression Interpolation: `${object.property.toUpperCase()}` evaluates any valid Dart expression inside the braces.
Raw Strings: Prefixing with `r` (`r"C:\path\new"`) disables escape sequence interpretation.
Multiline Strings: Triple single/double quotes (`"""..."""`) preserve newlines and indentation.
Syntax Blueprint
var msg = "Item: $name, Price: ${price * 1.1}";
var multi = """\nLine 1\nLine 2\n""";
var raw = r"No \n escape interpretation";Expressive string creation patterns in modern Dart.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using `${var}` for simple variables instead of `$var`.Why it happens: Both work, but `$var` is cleaner and the idiomatic Dart style.
How to fix: Use `$name` for simple identifiers and `${user.name}` only when accessing properties or methods.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Format Product Summary
Given `String product = "Flutter Book";` and `double price = 39.95;`.
Print `Product: $product costs $$price (Discount: ${price * 0.9})`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.