Dart Language Basics & Syntax
7 questions foundWhat is Dart, and why did Google choose it as the programming language specifically designed to power the Flutter framework?
Beginner Dart is a modern, object oriented programming language created by Google, designed to be easy to learn for developers already familiar with languages like Java, JavaScript, or C sharp, while also compiling extremely efficiently to native machine code for excellent runtime performance, and Google specifically chose Dart for Flutter because its support for both fast just in time compilation during development, enabling instant hot reload, and ahead of time compilation for release builds, gives Flutter apps a genuinely strong combination of fast development iteration and excellent final production performance.
void main() {
print('Hello, Flutter!');
}
Real-world example A developer new to Flutter but already experienced with JavaScript finds Dart's syntax immediately familiar and approachable, becoming comfortably productive writing Flutter code within just their first few days of learning.
Common follow-ups: How does Dart's performance compare to JavaScript or Java?;What other frameworks or platforms besides Flutter use the Dart language?
Dart Null Safety;Flutter Widgets Fundamentals (Stateless & Stateful)
What are the basic variable declaration keywords in Dart, specifically var, final, and const, and how do they differ from each other?
Beginner The var keyword declares a variable whose value can be reassigned later, with Dart automatically inferring its specific type based on the initial assigned value, final declares a variable that can only ever be assigned its value exactly once, though that assignment can happen at runtime, and const declares a genuinely compile time constant, meaning its value must be fully known and fixed at compile time itself, and choosing the most restrictive appropriate option among these three, generally preferring const or final over var whenever reasonably possible, helps prevent accidental, unintended reassignment mistakes.
var count = 5; // Can be reassigned
final name = 'Alex'; // Assigned once, but value determined at runtime
const pi = 3.14159; // Fixed at compile time
Real-world example A developer declares a widget's fixed padding value using const specifically because that exact value will never change, allowing Dart's compiler to optimize that specific value more efficiently than if it had been declared using var.
Common follow-ups: What happens if you try to reassign a value to a variable declared with final?;When would you use var instead of always simply preferring final?
Dart Null Safety;Dart Collections & Generics
What are named parameters and positional parameters in Dart functions, and how does using curly braces to declare parameters as named improve the readability of a function call with many arguments?
Intermediate Dart functions can accept parameters either positionally, meaning arguments must be passed in a fixed specific order matching the function's declaration, or as named parameters, declared using curly braces, which lets a caller explicitly specify each individual argument's own corresponding name when calling the function, and named parameters are especially valuable for functions accepting many different parameters, since explicitly naming each argument at the actual call site makes the resulting code significantly more self documenting and considerably harder to accidentally call with arguments passed in the wrong order.
void createUser({required String name, required int age, String? email}) {
print('$name is $age years old');
}
createUser(name: 'Alex', age: 30);
Real-world example A function for creating a new user account uses named parameters for name, age, and an optional email, making a call site like createUser(name: Alex, age: 30) immediately self explanatory, compared to an equivalent purely positional call that would be far more difficult to correctly interpret at a glance.
Common follow-ups: What is the difference between a required named parameter and an optional positional parameter?;Can a single function mix both named and positional parameters together?
Dart Collections & Generics;Flutter Widgets Fundamentals (Stateless & Stateful)
How does Dart's cascade notation, using consecutive dot operators, let you call multiple methods on the same object in a clean, concise, and chainable style?
Intermediate Cascade notation, written using two consecutive dots, lets you perform a whole sequence of separate operations on exactly the same object without needing to explicitly repeat that object's variable name before every single individual method call or property assignment, which is especially useful and commonly seen when configuring an object with many separate properties or calling several separate methods on it in sequence, resulting in noticeably more concise and readable code compared to writing out each individual statement fully separately.
final paint = Paint()
..color = Colors.blue
..strokeWidth = 2.0
..style = PaintingStyle.stroke;
Real-world example A custom drawing routine configures a Paint object's color, stroke width, and style all together using cascade notation, avoiding the need to repeat the word paint before each individual separate property assignment.
Common follow-ups: What is the difference between the single dot operator and the double dot cascade operator?;Can cascade notation be combined with a null aware operator for an object that might actually be null?
Custom Painters & CustomPaint;Flutter Widgets Fundamentals (Stateless & Stateful)
What are extension methods in Dart, and how do they let you add new useful functionality directly onto an existing class, including classes you did not originally write yourself, such as Dart's own built in String class?
Intermediate An extension method lets you effectively add a brand new method or property directly onto an existing class from outside of that class's own original definition, including built in Dart classes or classes that come from an external third party package that you cannot directly modify yourself, and this is especially useful for adding small, genuinely convenient helper functionality, such as a method that checks whether a String is a validly formatted email address, in a way that reads naturally as if that method had always been a fully native, built in part of that original class all along.
extension StringValidation on String {
bool get isValidEmail => contains('@') && contains('.');
}
print('test@example.com'.isValidEmail); // true
Real-world example A form validation utility adds an isValidEmail extension method directly onto Dart's built in String class, letting any string throughout the entire codebase be validated with the simple, natural sounding syntax myString.isValidEmail.
Common follow-ups: Can an extension method override an already existing method defined on the original class?;What happens if two separate imported extensions both happen to define a method with the exact same name?
Forms & Input Validation in Flutter;Dart Collections & Generics
How does pattern matching, introduced through Dart's more modern switch expressions and destructuring, let you write more concise and expressive code when handling different possible shapes of data?
Advanced Modern Dart versions introduced significantly more powerful pattern matching capabilities, including switch expressions that can directly return a value based on which specific pattern matches, along with destructuring, meaning extracting individual specific values directly out of a list, map, or object in a single concise step, and together these features let you write noticeably more concise, readable code when handling data that could take on several distinct possible different shapes, replacing what would otherwise require considerably more verbose conditional logic using traditional if else chains.
String describe(Object value) => switch (value) {
int n when n > 0 => 'positive number',
String s => 'a string: $s',
_ => 'something else',
};
Real-world example A data processing function uses a modern switch expression with pattern matching to cleanly handle several different possible incoming data shapes in one single concise expression, replacing what would have previously required a considerably longer, more verbose chain of separate if else statements.
Common follow-ups: What is the difference between a switch statement and a newer switch expression in Dart?;How does destructuring work specifically with Dart records?
Dart Null Safety;Dart Collections & Generics
What are Dart records, and how do they let you group together several distinct values of potentially different types without needing to first define an entirely separate dedicated class?
Advanced A record is a lightweight, anonymous data structure that lets you group together several distinct individual values, potentially of entirely different types, into one single combined value, without needing to first formally define an entirely separate dedicated class purely to represent that specific grouped shape of data, which is especially convenient for situations like a function that genuinely needs to return two or more distinct related values together, avoiding the overhead of defining a small dedicated wrapper class solely for that one single specific purpose.
(double, double) getScreenDimensions() {
return (400.0, 800.0);
}
final (width, height) = getScreenDimensions();
Real-world example A utility function calculating both a discounted price and the total amount actually saved returns both of those distinct values together as a single record, avoiding the need to define an entirely separate small dedicated class purely to hold just those two specific related values.
Common follow-ups: What is the difference between a record and defining a proper full class?;Can a record have named fields in addition to purely positional ones?
Dart Collections & Generics;Dart Null Safety