Created by Daniyal Ahsan
Welcome to the Dart Learning Repository! This repository is a self-paced, structured hands-on tutorial designed to take you from a complete beginner to writing clean, idiomatic Dart programs.
Dart is a client-optimized language developed by Google, famous for powering Flutter (for building beautiful cross-platform mobile, web, and desktop apps) and highly performant backend frameworks like Shelf or Dart Frog.
The course is organized into sequential modules. Each module covers a core concept of the Dart language.
| Module | Topic | Core Focus | Files |
|---|---|---|---|
| 01 | Introduction to Dart | Dart Overview, SDK Installation, main() entrypoint |
notes.md |
| 02 | Input & Output Basics | Using print(), standard input via stdin.readLineSync(), Null Safety intro |
notes.md, example.dart, exercise.dart |
| 03 | Variables & Keywords | Mutable and immutable declarations with var, final, const, and dynamic |
notes.md, example.dart, exercise.dart |
| 04 | Data Types | Working with int, double, String, bool, List, and Map collections |
notes.md, example.dart, exercise.dart |
| 05 | Operators | Arithmetic, Comparison, Logical, and Assignment operators | notes.md, example.dart, exercise.dart |
| 06 | Control Flow | Conditional branching (if-else, switch) and loops (for, while, do-while) |
notes.md, example.dart, exercise.dart |
| 07 | Functions | Functions, arrow functions, named and optional parameters, string interpolation | notes.md, example.dart, exercise.dart |
| 08 | Null Safety | Nullable and non-nullable types, null assertions (!), null-aware operators (??, ??=), late variables |
notes.md, example.dart, exercise.dart |
| 09 | Collections | Working with lists, sets, and maps, common collection methods, key-value structures, and loops | notes.md, example.dart, exercise.dart |
| 10 | OOP: Classes & Objects | Object-Oriented Programming basics including classes, objects, default/named constructors, and methods | notes.md, example.dart, exercise.dart |
| 11 | Inheritance, Interfaces & Mixins | OOP inheritance, abstract classes, interfaces (implements), mixins (with), and method overriding |
notes.md, example.dart, exercise.dart |
| 12 | Exceptions & Generics | Exception handling (try-catch, custom exceptions) and generic programming basics |
notes.md, example.dart, exercise.dart |
| 13 | Asynchronous Programming | Asynchronous Dart, async, await, Futures, error handling, parallel execution | notes.md, example.dart, exercise.dart |
| 13b | Streams & Async Error Handling | Asynchronous streams, async*, yield, stream listening (await for, .listen), stream operations, async error handling | notes.md, example.dart, exercise.dart |
| 14 | Introduction to Flutter | Flutter UI toolkit, Widget tree, StatelessWidget vs StatefulWidget, state management with setState() |
notes.md, example.dart, exercise.dart, counter_app/, solutions/flutter_intro |
Once you have mastered the core language features, put your skills to the test with these console mini-projects located in the practical/ directory:
- CLI Calculator (calculator.dart): A command-line calculator that takes user inputs, processes arithmetic operators (+, -, *, /), and includes zero-division safety.
- Multi-Unit Temperature Converter (temperature-convertor.dart): A robust CLI tool that converts temperatures across Celsius, Fahrenheit, and Kelvin through a user-friendly selection menu.
- Text-Based Quiz App (text-based-quiz-app.dart): An interactive quiz game that prompts the user with questions, validates responses, updates scores, and provides performance feedback.
- Contact Manager (contact_manager.dart): An object-oriented CLI system managing contact creation, deletion, search, and list, incorporating custom exception handling.
- Weather App (main.dart): A console app that fetches live weather data from the Open-Meteo API using async/await, HTTP requests, and JSON parsing.
To run the practical projects, run the following commands in your terminal:
dart run practical/calculator.dart
dart run practical/temperature-convertor.dart
dart run practical/text-based-quiz-app.dart
dart run practical/contact_manager.dart
dart run practical/Weather_App/main.dartTo strengthen your problem-solving abilities and understand execution flow, try these exercises located in the logic-building/ directory (see the full Problem Set). They cover fundamental algorithms using both iterative and recursive approaches:
- Sorting Algorithms:
- Bubble Sort (bubble-sort.dart)
- Merge Sort (merge-sort.dart)
- Search Algorithms:
- Linear Search (linear-search.dart)
- Binary Search (binary-search.dart)
- Standard Logic:
- FizzBuzz (fizzbuzz.dart)
- Palindrome Check (plaindrome.dart)
- Reverse Number (reverse-number.dart)
- Iteration vs. Recursion:
- Factorial (factorial.dart & factorial-recursive.dart)
- Fibonacci (fibonacci.dart & fibonacci-recursive.dart)
- Sum of 1 to N (sum-of-1-to-N.dart & sum-of-1-to-N-recursive.dart)
- Recursive Thinking:
- Recursive Countdown (recursive-countdown.dart)
- Digit Counter (digit-counter-recursive.dart)
- Power Calculator (recursive-power-calculator.dart)
- Arrays & Lists:
- Find Maximum (find_maximum.dart)
- Find Minimum (find_minimum.dart)
- Sum of Elements (sum_of_elements.dart)
- Even and Odd Counter (count_even_odd.dart)
- Remove Duplicates (remove_duplicates.dart)
- Reverse List Manually (reverse_list.dart)
- String Manipulation:
- Count Vowels (count_vowels.dart)
- Count Word Occurrences (count_word_occurrences.dart)
- Capitalize Each Word (capitalize_words.dart)
- Find Longest Word (find_longest_word.dart)
- Hash Maps (Dart
Map):- Character Frequency (character_frequency.dart)
- Word Frequency (word_frequency.dart)
- First Non-Repeating Character (first_non_repeating_character.dart)
- Group Even and Odd (group_by_even_odd.dart)
To run a logic-building script, use:
dart run logic-building/<filename>.dartFollow these steps to set up your local development environment:
-
Install Dart SDK:
- Download and install the Dart SDK from the Official Dart website.
- Alternatively, install Flutter, which comes pre-bundled with the Dart SDK.
-
Set Up VS Code:
- Install Visual Studio Code.
- Open the VS Code Extensions tab (
Ctrl+Shift+XorCmd+Shift+X) and install the Dart extension.
-
Clone this Repository:
git clone <repository-url> cd dart-learning
To get the most out of this repository, follow this learning loop for each module:
graph TD
A[Read Module notes.md] --> B[Run example.dart]
B --> C[Write solution in exercise.dart]
C --> D[Run your exercise.dart code]
D --> E[Compare with solutions/ folder]
-
Read
notes.md: Study the concepts, vocabulary, syntax rules, and cheat sheets in the directory. -
Analyze
example.dart: Run the example code using the terminal to see how the syntax behaves.dart run <module-folder>/example.dart
-
Practice: Open
exercise.dart(which is kept blank for you) and write a program that satisfies the exercise instructions found at the bottom of that module'snotes.md. -
Test: Run your custom exercise code:
dart run <module-folder>/exercise.dart
-
Review: Check your answers against the corresponding file in the solutions/ directory to see how it can be structured.
Unlike modules 01-13b which contain standalone Dart console programs run using dart run, Flutter modules require a Flutter environment to execute widgets.
For Module 14 (Introduction to Flutter):
-
Running the Example: The example code in example.dart is pre-configured as a runnable Flutter project in the counter_app/ directory. To run it, navigate to that directory and start the application:
cd 14-flutter-intro/counter_app flutter run -
Completing the Exercise:
- Write your widget code in exercise.dart according to the task description in the
notes.md. - To run and test your widgets, copy and paste them into counter_app/lib/main.dart (replacing the example code) and run
flutter run.
- Write your widget code in exercise.dart according to the task description in the
-
Checking the Solution:
- Compare your code with the single-file solution in solutions/14-flutter-intro.dart.
- Alternatively, you can run the completed solution project:
cd solutions/flutter_intro flutter run
- Naming Conventions: Variables and functions in Dart should use
camelCase(e.g.,favoriteFood,userAge). - Null Safety: When reading input with
stdin.readLineSync(), Dart returns a nullable String (String?). Keep this in mind when defining variable types. - Run Anywhere: Since Dart compiles to standalone machine code or JavaScript, the skills you learn here translate directly to writing backend APIs, command-line utilities, or Flutter apps.
Dart is the foundational programming language that powers Flutter. Mastering core Dart concepts—like null safety, control flow, and collections—prevents common errors and makes building cross-platform mobile and web interfaces in Flutter significantly easier.
varis used when you want Dart to infer the variable type, and the value can be changed.finalis used for variables whose values are set only once at runtime (e.g., fetching data from an API).constis used for variables whose values are completely fixed and known at compile-time (e.g., hardcoded UI values).
Null safety ensures that variables cannot contain a null value unless you explicitly allow them to by adding a question mark (e.g., String?). This feature eliminates a massive class of runtime errors, making your Flutter apps much more stable.
No prior experience is strictly required, though familiarity with basic programming concepts helps. This curriculum is structured step-by-step, starting from basic SDK installation and I/O, moving up to functions and null safety, complete with hands-on exercise.dart files to practice.
Yes! While Dart is famous for Flutter mobile and web apps, it compiles to standalone machine code. You can use frameworks like Shelf or Dart Frog to write highly performant backend servers and command-line utilities.
Happy Coding! If you find this repository helpful, consider leaving a star!