Skip to content

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn Dart Programming: Step-by-Step

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.


Curriculum Roadmap

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

Practical Mini-Projects

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.dart

Logic Building & Recursion

To 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:

To run a logic-building script, use:

dart run logic-building/<filename>.dart

Getting Started

Follow these steps to set up your local development environment:

  1. 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.
  2. Set Up VS Code:

    • Install Visual Studio Code.
    • Open the VS Code Extensions tab (Ctrl+Shift+X or Cmd+Shift+X) and install the Dart extension.
  3. Clone this Repository:

    git clone <repository-url>
    cd dart-learning

Guided Learning Workflow

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]
Loading
  1. Read notes.md: Study the concepts, vocabulary, syntax rules, and cheat sheets in the directory.

  2. Analyze example.dart: Run the example code using the terminal to see how the syntax behaves.

    dart run <module-folder>/example.dart
  3. 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's notes.md.

  4. Test: Run your custom exercise code:

    dart run <module-folder>/exercise.dart
  5. Review: Check your answers against the corresponding file in the solutions/ directory to see how it can be structured.

đź’ˇ Special Case: Flutter Modules (Module 14+)

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):

  1. 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
  2. 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.
  3. 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

Key Tips & Conventions

  • 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.

Frequently Asked Questions (FAQ)

Why should I learn Dart before Flutter?

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.

What is the difference between var, final, and const in Dart?

  • var is used when you want Dart to infer the variable type, and the value can be changed.
  • final is used for variables whose values are set only once at runtime (e.g., fetching data from an API).
  • const is used for variables whose values are completely fixed and known at compile-time (e.g., hardcoded UI values).

How does Null Safety work in Dart?

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.

Do I need prior programming experience to use this repository?

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.

Can I build backend APIs with Dart?

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!

Releases

Packages

Used by

Contributors

Languages