Watch the video (14 min)
On this page26 sections
  1. Prerequisites
  2. Connection With Previous Lectures
  3. Learning Objectives
  4. 1. What Is a Programming Language?
  5. 2. What Is Dart?
  6. 3. A First Look at Dart Code
  7. 4. Instructions Run in Order
  8. 5. Dart Can Calculate
  9. 6. A Short History of Dart
  10. 7. Where Dart Runs
  11. 8. How Dart Runs Your Code
  12. 9. Dart Checks Your Code Before It Runs
  13. 10. Null Safety in One Sentence
  14. 11. Dart and Flutter
  15. 12. Why Learn Dart?
  16. 13. How This Course Works
  17. 14. A Real-World Example
  18. Code Examples
  19. Common Beginner Mistakes
  20. Best Practices
  21. Mini Challenge
  22. Practice Questions
  23. Practice Answers
  24. Quick Revision
  25. Key Takeaways
  26. What's Next?

Lecture 01 — Introduction to Dart & Why Learn It

Category1 — Dart Fundamentals
Lecture001 of 140
Estimated video length14 min
TargetDart 3.12.2
LevelBeginner

A computer does exactly what it is told, but it does not understand English. A programming language like Dart lets you write instructions that a person can read and a computer can follow.

Contents

Prerequisites · Connection · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Mini Challenge · Practice Questions · Answers · Takeaways

Every error message in this lecture is real. Each one was produced by running the code shown on Dart 3.12.2, so you will recognize it when you meet it yourself.


Prerequisites

This is the first lecture of the course. You need:

  • a computer (Windows, macOS, or Linux)
  • an internet connection
  • no programming experience at all

You do not need Dart installed yet. The code in this lecture is a preview: read it now, and run it yourself after Lecture 002, which installs everything.


Connection With Previous Lectures

There is no previous lecture, so let us start with the problem every programmer faces.

Suppose Ali wants his computer to add up his three exam marks — 80, 75, and 85 — and show the total. He could type "please add my marks" into the computer, and nothing would happen. A computer cannot read ordinary language. It only follows precise instructions written in a form it can process. To give it those instructions, Ali needs a programming language. This course teaches one: Dart.


Learning Objectives

By the end of this lecture you will be able to:

  • Explain what a programming language is
  • Describe what Dart is and who created it
  • Read a very small Dart program and predict its output
  • List the platforms where Dart programs can run
  • Explain, in simple terms, how Dart runs and compiles your code
  • Describe how Dart catches mistakes before a program runs
  • Explain the relationship between Dart and Flutter
  • Give several practical reasons to learn Dart

1. What Is a Programming Language?

A programming language is a set of words and rules for writing instructions a computer can carry out. A file of those instructions is called a program, and writing it is called programming (or coding).

Analogy — think of a recipe. A recipe lists exact steps in a fixed order: "boil water, add rice, wait 15 minutes". The cook does not guess; they follow each step. A program is a recipe for the computer, and the programming language is the strict format the recipe must be written in.

There are many programming languages — Python, JavaScript, Java, Swift, Kotlin, and others. Each has its own words and rules. Dart is one of them.


2. What Is Dart?

Dart is a programming language created at Google. It is:

  • general-purpose — you can build many kinds of programs with it, not just one kind
  • free and open source — anyone can use it, read its source code, and contribute
  • modern — it was designed recently, learning from older languages' mistakes
  • type-safe — it checks your code for many mistakes before the program runs

Dart is best known as the language behind Flutter, Google's toolkit for building apps. This course teaches the Dart language itself — no Flutter — so that you understand the language completely before you use any framework built on it.


3. A First Look at Dart Code

Here is a complete Dart program:

dart
void main() {
  print('Hello, Dart!');
}
output
Hello, Dart!

The line print('Hello, Dart!'); tells the computer to display the text between the quotes. Everything else is the frame that every Dart program needs. We will study main() and print() line by line in Lecture 003. For now, just notice how readable it is.


4. Instructions Run in Order

A program can hold many instructions. Dart runs them one after another, from top to bottom:

dart
void main() {
  print('Hello, Dart!');
  print('My name is Ali.');
  print('I am learning to program.');
}
output
Hello, Dart!
My name is Ali.
I am learning to program.

Each print produces one line of output, in the same order as the code. Just like the recipe: step one, then step two, then step three.


5. Dart Can Calculate

Computers are very good at arithmetic. Put a calculation inside print() — without quotes — and Dart prints the result:

dart
void main() {
  print(2 + 3);
  print(500 * 3);
  print(10 / 4);
}
output
5
1500
2.5

* means multiply and / means divide. This is exactly what Ali needed: Dart can add his marks for him. We will study arithmetic properly in Lecture 017 — Arithmetic & Assignment Operators.


6. A Short History of Dart

YearMilestone
2011Google announces Dart publicly
2013Dart 1.0 — the first stable version
2018Dart 2 — a stricter, safer type system; Flutter 1.0 is released
2021Dart 2.12 — null safety arrives
2023Dart 3 — null safety becomes mandatory; records and patterns arrive
TodayDart 3.12 — the version this course targets

You don't need to remember dates. The point is that Dart is mature — over a decade old — and still actively improved, with new versions released several times a year. We will look at how Dart versions work in Lecture 128 — Dart Language Evolution & Versioning.


7. Where Dart Runs

One language, many destinations:

PlatformWhat you can build
Command linetools and scripts that run in a terminal
Serversback-end programs that answer requests from apps and websites
Webprograms that run in a browser (Dart is converted to JavaScript or WebAssembly)
Mobile & desktopAndroid, iOS, Windows, macOS, and Linux apps, through Flutter

In this course, every program runs on the command line. It is the simplest place to learn, because nothing distracts from the language itself. Everything you learn here carries over unchanged to the other platforms.


8. How Dart Runs Your Code

The computer's processor does not understand Dart directly. Your code has to be compiled — translated into instructions the machine can execute. Dart can do this in two ways:

  • JIT (Just-In-Time) — while you are developing, Dart translates your code as it runs. You change a line, run it again, and see the result in seconds.
  • AOT (Ahead-Of-Time) — when your program is finished, Dart translates all of it in advance into a fast, standalone program that starts instantly.

You get quick experiments while learning and fast programs when you ship. In this course, you will mostly use the first way, with the dart run command. We will build standalone programs with the Dart command-line tool in Lecture 113 — Dart CLI.


9. Dart Checks Your Code Before It Runs

Dart knows what kind of value each thing is — text or a number, for example — and refuses to mix them carelessly. This program tries to add a number to a piece of text:

dart
void main() {
  print('Total: ' + 5);
}
output
Error: A value of type 'int' can't be assigned to a variable of type 'String'.
  print('Total: ' + 5);
                    ^

The program never starts. Dart reports the mistake, points at it with ^, and waits for you to fix it. Catching a mistake on your own screen is far better than having a user discover it later. int and String are the names Dart uses for whole numbers and text — you will meet them in Lecture 004.


10. Null Safety in One Sentence

Many programs crash because they try to use a value that is missing — in programming, a missing value is called null. Dart's null safety means the language tracks which values may be missing and makes you handle them, so this whole family of crashes is caught before the program runs. We will study it fully in Category 3, starting with Lecture 012 — Introduction to Null Safety.


11. Dart and Flutter

Flutter is a toolkit for building apps with buttons, screens, and animations. Flutter apps are written in Dart. Think of it this way: Dart is the language, and Flutter is one big project written in that language.

That makes the order of learning clear. If you know Dart well, Flutter is mostly about learning its building blocks. If you start Flutter without knowing Dart, you are learning two things at once, and every error message becomes harder to understand. This course gives you the language first.


12. Why Learn Dart?

  • It is beginner-friendly. Dart's code reads cleanly, and its error messages say plainly what went wrong and where.
  • One language, many platforms. The same skills work on the command line, servers, the web, and — with Flutter — phones and desktops.
  • It opens the door to Flutter. Flutter is one of the most popular ways to build apps for Android and iOS from a single codebase, and companies hire Flutter developers.
  • It catches mistakes early. Type safety and null safety find many bugs before your program runs.
  • The tools are built in. Dart comes with a formatter, an analyzer that spots problems, a testing framework, and a package manager. Each one gets its own lecture in Categories 19 and 20.
  • Skills transfer. Dart looks familiar to anyone who knows Java, JavaScript, C#, or Kotlin — and what you learn here will make those languages easier later.
  • It is modern. Features such as records, patterns, and sealed classes (Category 13) let you write short, safe code.

13. How This Course Works

The course has 140 lectures in 23 categories, ordered so that every idea arrives only after everything it depends on. Each lecture follows the same plan:

  1. short lesson steps, each with a snippet and its real output
  2. ten complete code examples
  3. common mistakes, with the real error messages
  4. a mini challenge, practice questions, and answers at the end

The most important rule: type the code yourself. Reading a program is not the same as writing it. Your fingers will make small mistakes, Dart will report them, and fixing them is how you learn.


14. A Real-World Example

Sara runs a small stationery shop. A customer buys 3 notebooks at 500 each and 4 pens at 40 each. Here is a tiny Dart program that prints the receipt:

dart
void main() {
  print('Shop: Sara Stationery');
  print('Notebook x 3');
  print(500 * 3);
  print('Pen x 4');
  print(40 * 4);
  print('Grand total:');
  print(500 * 3 + 40 * 4);
}
output
Shop: Sara Stationery
Notebook x 3
1500
Pen x 4
160
Grand total:
1660

It combines everything from this lecture: instructions running in order, text in quotes, and calculations without quotes. Dart multiplies before it adds, just as in school maths, so the grand total is 1500 + 160. In Lecture 004 you will learn to store values like 500 in variables, so a price is typed once instead of twice.


Code Examples

Each example is a complete program. After Lecture 002, copy one into a file and run it with dart run.

Example 1 — Hello, World

dart
void main() {
  print('Hello, World!');
}
output
Hello, World!

Example 2 — Several Lines of Text

dart
void main() {
  print('Name: Sara');
  print('City: Lahore');
  print('Learning: Dart');
}
output
Name: Sara
City: Lahore
Learning: Dart

Example 3 — Printing Numbers

dart
void main() {
  print(42);
  print(3.14);
  print(-7);
}
output
42
3.14
-7

Example 4 — Four Basic Calculations

dart
void main() {
  print(10 + 5);
  print(10 - 5);
  print(10 * 5);
  print(10 / 5);
}
output
15
5
50
2.0

How it works

  1. +, -, and * on whole numbers give whole numbers.
  2. / always gives a decimal result, so 10 / 5 prints 2.0, not 2.
  3. Lecture 009 — Numbers explains why.

Example 5 — Drawing with Text

dart
void main() {
  print('*****');
  print('*   *');
  print('*****');
}
output
*****
*   *
*****

Text inside quotes is printed exactly as written — spaces included.

Example 6 — Order Matters

dart
void main() {
  print('Step 1: Wake up');
  print('Step 2: Open the laptop');
  print('Step 3: Write Dart');
}
output
Step 1: Wake up
Step 2: Open the laptop
Step 3: Write Dart

Swap two lines in the code and the output lines swap too.

Example 7 — Student Marks

dart
void main() {
  print('Student: Ali');
  print('Total marks:');
  print(80 + 75 + 85);
}
output
Student: Ali
Total marks:
240

How it works

  1. The first two lines print text, exactly as written.
  2. The third line has no quotes, so Dart calculates 80 + 75 + 85 and prints the result.
  3. This is the problem from the start of the lecture, solved.

Example 8 — Shopping Total

dart
void main() {
  print('Notebook: 500 each, 3 bought');
  print('Total:');
  print(500 * 3);
}
output
Notebook: 500 each, 3 bought
Total:
1500

How it works

  1. The numbers in the first line are inside quotes, so they are just text — Dart does not calculate anything there.
  2. 500 * 3 is outside quotes, so Dart multiplies and prints 1500.

Example 9 — Bank Balance

dart
void main() {
  print('Piggy bank: Zayan');
  print('Starts at 150, gets 50, spends 30');
  print(150 + 50 - 30);
}
output
Piggy bank: Zayan
Starts at 150, gets 50, spends 30
170

How it works

  1. Dart works through 150 + 50 - 30 from left to right.
  2. 150 + 50 is 200, and 200 - 30 is 170.

Example 10 — Temperature Conversion

dart
void main() {
  print('25 degrees Celsius in Fahrenheit:');
  print(25 * 9 / 5 + 32);
}
output
25 degrees Celsius in Fahrenheit:
77.0

How it works

  1. The formula is: multiply by 9, divide by 5, add 32.
  2. 25 * 9 is 225, and 225 / 5 is 45.0 — a decimal, because of /.
  3. 45.0 + 32 is 77.0.

Common Beginner Mistakes

1. Thinking Dart is only for Flutter

Flutter made Dart famous, but Dart runs on its own — on the command line, on servers, and on the web. Every program in this course runs without Flutter.

2. Writing Print with a capital P

dart
void main() {
  // Print('Hello, Dart!'); // ✗
}
output
Error: Method not found: 'Print'.

Dart is case-sensitive: print and Print are different names. Use lowercase print.

3. Forgetting the semicolon

dart
void main() {
  // print('Hello, Dart!') // ✗ no ; at the end
}
output
Error: Expected ';' after this.

Each instruction in Dart ends with ;, like a full stop at the end of a sentence.

4. Forgetting the quotes around text

dart
void main() {
  // print(Hello); // ✗
}
output
Error: Undefined name 'Hello'.

Without quotes, Dart thinks Hello is the name of something in your program — and there is nothing called Hello. Text needs quotes: print('Hello');.

5. Trying to run code before installing Dart

If you type dart into a terminal before Lecture 002, you will see something like:

output
zsh:1: command not found: dart

That is not a mistake in your code — the computer simply doesn't have Dart yet. The exact wording depends on your operating system.

6. Trying to understand everything at once

You will see words like void and main before they are explained. That is normal. Each one gets its own lecture. Focus on what the current lecture teaches.


Best Practices

  • Type every example yourself instead of copying and pasting.
  • Run the code, then change one thing and predict the new output before running it again.
  • Read error messages slowly — Dart tells you what went wrong and points to where.
  • Learn the language first; frameworks such as Flutter come afterwards.
  • Study in order. Each lecture builds on the ones before it.
  • Do the practice questions before opening the answers.

Mini Challenge

Write a welcome card for Sara. Print a greeting, a line listing her three test marks — 85, 90, and 78 — then let Dart calculate and print their total.

Your program should print exactly:

output
Welcome to the Dart course, Sara!
Your three test marks: 85, 90, 78
Total:
253

Try it yourself before opening the solution.

Show solution
dart
void main() {
  print('Welcome to the Dart course, Sara!');
  print('Your three test marks: 85, 90, 78');
  print('Total:');
  print(85 + 90 + 78);
}
output
Welcome to the Dart course, Sara!
Your three test marks: 85, 90, 78
Total:
253

How it works

  1. The first three lines are text in quotes, printed exactly as written.
  2. The last line has no quotes, so Dart adds 85 + 90 + 78 and prints 253.

Practice Questions

Work through these in order — they run from beginner to application to challenge. Write the programs now and run them after Lecture 002.

Beginner

  1. In one sentence, what is a programming language?
  2. Name the four kinds of platforms Dart programs can run on.
  3. What is the relationship between Dart and Flutter?

Application

  1. Write a program that prints Hello, Sara!.

  2. Write a program that prints three lines: Name: Zayan, City: Karachi, and Favourite language: Dart.

  3. A shop sells a bag for 1200. Write a program that lets Dart calculate and print the cost of 3 bags.

  4. Predict the output of this program before checking the answer:

    dart
    void main() {
      print(10 + 4);
      print(10 / 4);
      print(10 * 4);
    }
  5. This program has two mistakes. Find and fix them, so that it prints two lines:

    dart
    void main() {
      Print('Dart is fun');
      print('Ali is learning it')
    }

Challenge

  1. Water boils at 100 degrees Celsius. Using the formula from Example 10, write a program that prints a label and then the temperature in Fahrenheit. Explain why the result ends in .0.
  2. Zayan buys 3 notebooks at 500 each and 2 pencils at 20 each, and pays with 2000. Write a receipt program that prints each item with its cost, the total, and his change.

Practice Answers

Question 1 — Solution

A programming language is a set of words and rules for writing instructions that a computer can carry out.

Question 2 — Solution

The command line, servers, the web (in a browser), and mobile and desktop apps (through Flutter).

Question 3 — Solution

Flutter is a toolkit for building apps, and Flutter apps are written in Dart. Dart is the language; Flutter is built with it. You can use Dart without Flutter, but not Flutter without Dart.

Question 4 — Solution

dart
void main() {
  print('Hello, Sara!');
}
output
Hello, Sara!

Question 5 — Solution

dart
void main() {
  print('Name: Zayan');
  print('City: Karachi');
  print('Favourite language: Dart');
}
output
Name: Zayan
City: Karachi
Favourite language: Dart

Question 6 — Solution

dart
void main() {
  print(1200 * 3);
}
output
3600

Question 7 — Solution

output
14
2.5
40

10 / 4 gives a decimal result, 2.5. The other two lines give whole numbers.

Question 8 — Solution

Print must be lowercase, and the second line is missing its semicolon:

dart
void main() {
  print('Dart is fun');
  print('Ali is learning it');
}
output
Dart is fun
Ali is learning it

Question 9 — Solution

dart
void main() {
  print('100 degrees Celsius in Fahrenheit:');
  print(100 * 9 / 5 + 32);
}
output
100 degrees Celsius in Fahrenheit:
212.0

The calculation includes a division with /, and / always produces a decimal number. Adding 32 to a decimal number gives a decimal number, so the result prints as 212.0.

Question 10 — Solution

dart
void main() {
  print('Customer: Zayan');
  print('Notebook x 3');
  print(500 * 3);
  print('Pencil x 2');
  print(20 * 2);
  print('Total:');
  print(500 * 3 + 20 * 2);
  print('Change from 2000:');
  print(2000 - (500 * 3 + 20 * 2));
}
output
Customer: Zayan
Notebook x 3
1500
Pencil x 2
40
Total:
1540
Change from 2000:
460

The brackets in the last line make Dart calculate the whole total first, then subtract it from 2000. Notice that 500 * 3 + 20 * 2 is typed three times — exactly the kind of repetition that variables remove in Lecture 004.


Quick Revision

  1. What is a program?
  2. Which company created Dart?
  3. In which order does Dart run the instructions in main()?
  4. What is the difference between print('5 + 3') and print(5 + 3)?
  5. What is the difference between JIT and AOT compilation?
  6. When does Dart report a type mistake — before or while the program runs?
  7. What is null, and what does null safety do?
  8. Why does this course teach Dart before Flutter?

Key Takeaways

  • A programming language is a precise way to give a computer instructions; a program is a file of those instructions.
  • Dart is a free, open-source, general-purpose language created at Google.
  • Dart runs instructions in order, top to bottom.
  • Text goes inside quotes; a calculation without quotes is worked out and its result printed.
  • Dart runs on the command line, servers, the web, and — through Flutter — mobile and desktop.
  • Dart compiles JIT for fast development and AOT for fast finished programs.
  • Type safety and null safety catch many mistakes before a program runs.
  • Flutter is written in Dart, so learning Dart first makes Flutter far easier.

What's Next?

Lecture 02 — Dart SDK & Development Environment. You have now seen what Dart code looks like, but your computer cannot run it yet. Next we will install the Dart SDK, set up a code editor, and run our very first program for real.


Video lecture

Subscribe
Placeholder video — the real recording isn't linked yet.