What does this print?
The $ sign in a string performs string interpolation: it inserts the value of the variable "name" into the string.
Learn just enough Dart to start building Flutter apps
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Before diving deeper into Flutter, you need to learn the essential Dart concepts that power every Flutter app. Dart is the programming language used by Flutter. It is clean, modern, and designed to be easy to pick up, even if you are new to programming.
Variables are used to hold values. Dart can figure out the type automatically based on what you assign:
1// 'var' lets Dart figure out the type2var name = 'Alice'; // String (text)3var age = 25; // int (whole number)4var height = 5.7; // double (decimal)5var isStudent = true; // bool (true/false)67// You can also declare the type explicitly:8String city = 'NYC';9int score = 100;10double price = 29.99;11bool isDarkMode = false;1213// Print to console14print('Hello, $name!'); // String interpolation15print('Age: ${age + 1}'); // Expression in string
Use `$variable` to insert a variable into a string. For expressions, use `${expression}` format, such as `${age + 1}`. This approach is much cleaner and easier to read than traditional string concatenation.
1// final: Set once, never changes (can be set at runtime)2final username = 'john_doe';3final now = DateTime.now(); // OK - computed at runtime45// const: Must be known at compile time6const pi = 3.14159;7const maxItems = 100;8// const now = DateTime.now(); // ERROR! Not known at compile time910// Rule of thumb:11// Use 'const' when you know the value before the app runs12// Use 'final' when the value is computed once at runtime
1// Basic function with return type2String greet(String name) {3return 'Hello, $name!';4}56// Arrow syntax (short form for one-line functions)7String greet(String name) => 'Hello, $name!';89// Function with no return value10void printMessage(String msg) {11print(msg);12}1314// Function with optional parameters15void createUser(String name, {int age = 18, String? city}) {16print('Name: $name, Age: $age, City: ${city ?? "Unknown"}');17}1819// Calling functions20print(greet('Alice')); // Hello, Alice!21createUser('Bob', age: 25); // Name: Bob, Age: 25, City: Unknown22createUser('Carol', city: 'NYC'); // Name: Carol, Age: 18, City: NYC
1// Create a list2var fruits = ['apple', 'banana', 'cherry'];3List<int> numbers = [1, 2, 3, 4, 5];45// Access items (0-indexed)6print(fruits[0]); // apple7print(fruits.length); // 389// Add & remove10fruits.add('date'); // Add to end11fruits.remove('banana'); // Remove by value12fruits.insert(1, 'blueberry'); // Insert at index1314// Loop through15for (var fruit in fruits) {16print(fruit);17}1819// Map (transform each item)20var caps = fruits.map((f) => f.toUpperCase()).toList();
1// Create a map2var user = {3'name': 'Alice',4'age': 25,5'city': 'NYC',6};78// Access values9print(user['name']); // Alice1011// Typed map12Map<String, dynamic> profile = {13'name': 'Bob',14'age': 30,15'scores': [95, 87, 92],16};
1// If/else2if (age >= 18) {3print('Adult');4} else if (age >= 13) {5print('Teen');6} else {7print('Child');8}910// Ternary (shorthand if/else) - used frequently in Flutter11var label = age >= 18 ? 'Adult' : 'Minor';1213// In Flutter widgets:14Text(isLoggedIn ? 'Welcome back!' : 'Please log in')15Icon(isFavorite ? Icons.favorite : Icons.favorite_border)
Flutter widgets are all classes. Here is how classes work in Dart:
1class User {2// Properties3final String name;4final int age;56// Constructor (creates the object)7User({required this.name, required this.age});89// Method10String greet() => 'Hi, I\'m $name!';11}1213// Using the class14var user = User(name: 'Alice', age: 25);15print(user.name); // Alice16print(user.greet()); // Hi, I'm Alice!
You do not need to memorize all of Dart right now. This is a quick overview to get you started. Each of these topics will be covered in more detail in Level 1. For now, focus on understanding the general patterns and how the different pieces fit together.
Here is how all of these Dart concepts come together inside a real Flutter widget:
1class ProfileCard extends StatelessWidget {2// Constructor with named parameters3final String name;4final int postCount;5final bool isVerified;67const ProfileCard({8required this.name,9required this.postCount,10this.isVerified = false,11});1213@override14Widget build(BuildContext context) {15return Column(16children: [17// String interpolation18Text('Hello, $name!'),1920// Ternary for conditional UI21Icon(isVerified ? Icons.verified : Icons.person),2223// Expression in string24Text('$postCount posts'),25],26);27}28}
You do not need advanced Dart yet, but you should be comfortable with these essentials:
If these points feel shaky, repeat this lesson once more with hands-on code edits.
Whenever you learn a Dart concept, immediately ask: where does this appear in a Flutter widget? This connection turns theory into practical app-building ability.
Learn just enough Dart to start building Flutter apps. Dart is the language behind Flutter, and clear Dart code makes your Flutter UI easier to maintain.
Build confidence with basics first; speed comes later.
Prefer readable names, explicit intent, and async/await over deeply nested callbacks.
When Dart basics are weak, state bugs, null crashes, and async confusion increase quickly.
The $ sign in a string performs string interpolation: it inserts the value of the variable "name" into the string.
final values are set once at runtime (e.g., DateTime.now()). const values must be known before the app runs (e.g., pi = 3.14).
Lists are 0-indexed in Dart. Index 0 = apple, Index 1 = banana, Index 2 = cherry.
The ternary operator checks if age >= 18 (true for 20), so it returns "Adult".
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue