Dart Fundamentals for Flutter
Dive into the basics of Dart programming, covering variables, data types, control flow, functions, and object-oriented concepts essential for Flutter.
Dart Fundamentals for Flutter is a free Flutter Mobile Development lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Flutter Mobile Development learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Welcome to Dart!
Before building apps, let’s learn Dart — Flutter’s language. It’s client-optimized and quick to pick up if you know Java or JavaScript.
Storing Data: Variables & Types
Variables store data. Declare them with var for inferred types, or be explicit: int, double, String, bool.
Variables in Action
Here’s declaring different variable types. Note Dart’s null safety: a variable can’t be null unless you opt in with ?.
void main() {
var name = "Alice"; // Type inferred as String
int age = 30;
double height = 1.75;
bool isStudent = true;
String? middleName; // Can be null
print("Name: $name");
print("Age: $age");
print("Student: $isStudent");
}Grouping Data: Lists
A Dart List is an ordered, zero-indexed collection — like an array. Declare a typed one like List<String> and grab items by position.
void main() {
List<String> fruits = ['Apple', 'Banana'];
print('Initial fruits: $fruits');
fruits.add('Orange'); // Add an item
print('After adding: $fruits');
print('First fruit: ${fruits[0]}');
}Making Decisions: If/Else
Control flow lets your code decide. if runs when a condition is true; chain else if and else for the rest.
void main() {
int temperature = 25;
if (temperature > 30) {
print('It\'s very hot!');
} else if (temperature > 20) {
print('It\'s warm.');
} else {
print('It\'s cool.');
}
}Repeating Actions: Loops
Loops repeat a block. A for loop is perfect for iterating a list or running a task a fixed number of times.
void main() {
List<String> colors = ['Red', 'Green', 'Blue'];
for (String color in colors) {
print('Color: $color');
}
for (int i = 0; i < 3; i++) {
print('Count: $i');
}
}Functions: Reusable Code
Functions are reusable blocks that do one task. They take parameters as input and can return a value as output.
Defining & Calling Functions
This shows two functions: greet takes a name, add returns an int. void means a function returns nothing.
void greet(String name) {
print('Hello, $name!');
}
int add(int a, int b) {
return a + b;
}
void main() {
greet('Coddy');
int sum = add(10, 5);
print('Sum: $sum');
}Basic Classes & Objects
Dart is object-oriented: a class is a blueprint for objects. Objects bundle properties (data) and methods (behavior) to keep code organized.
class Car {
String brand; // Property
int year; // Property
Car(this.brand, this.year); // Constructor
void displayInfo() { // Method
print('$brand from $year');
}
}
void main() {
var myCar = Car('Toyota', 2020); // Create an object
myCar.displayInfo(); // Call a method
var otherCar = Car('Honda', 2022);
otherCar.displayInfo();
}Dart Fundamentals Check
Which of the following Dart code snippets are valid variable declarations or initializations?
Recap: Dart Essentials
Nice work! You’ve got Dart’s core building blocks — variables, lists, control flow, loops, functions, and classes. This is the foundation for every Flutter app.
Frequently asked questions
Is the “Dart Fundamentals for Flutter” lesson free?
Yes — the full text of “Dart Fundamentals for Flutter” is free to read here on the web, and the Flutter Mobile Development course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Flutter Mobile Development course, upgrade to CoddyKit PRO.
What will I learn in “Dart Fundamentals for Flutter”?
Dive into the basics of Dart programming, covering variables, data types, control flow, functions, and object-oriented concepts essential for Flutter. You practise Flutter Mobile Development with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Flutter Mobile Development?
No prior experience is required. Flutter Mobile Development on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Dart Fundamentals for Flutter” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Flutter Mobile Development lesson?
Yes. Every Flutter Mobile Development lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Flutter Ecosystem & Setup
- Dart Fundamentals for Flutter
- Building Your First Flutter App
- Asynchronous Programming with Futures and async/await