📚

Dart Programming Language Overview

Apr 26, 2025

Dart Programming Language Tutorial by Mahmoud Asan

Introduction

  • Dart is the main programming language for developing cross-platform mobile applications using the Flutter framework.
  • Suitable for those familiar with other programming languages.

Installing Dart SDK

  • Visit the Dart website to download the SDK.
  • Dart SDK has versions for Windows, Linux, and Mac.
  • Visual Studio Code is recommended for writing Dart code.
  • DartPad (dartpad.dartlang.org) can be used to write and run Dart code online without installation.

Basic Setup

  • Install Dart extension in Visual Studio Code for syntax highlighting.
  • Use the built-in terminal in Visual Studio Code to run Dart code.

Features of Dart

Dart Basics

  • Dart is a static and compiled programming language.
  • Supports both Ahead of Time (AOT) and Just In Time (JIT) compilation.
  • Variables are defined with var, String, int, double, etc.
  • Supports dynamic type with dynamic keyword.
  • Main function syntax: void main() {}.

Variables

  • Type inference: Dart automatically infers the variable type.
  • Example: var firstName = "Muhammad"; infers String type.
  • Supports string interpolation using $.

Comments

  • Inline comments: // comment
  • Block comments: /* comment */
  • Documentation comments: /// comment

Data Types

  • Basic types: int, double, String, bool, dynamic.
  • Supports type conversion using int.parse(), double.parse(), .toString().
  • Constants are defined using const and final.

Operators

  • Standard operators: +, -, *, /, %.
  • Relational operators: ==, !=, >, <, >=, <=.
  • Logical operators: &&, ||, !.*

Conditional Statements

  • if, else if, else for conditional logic.
  • switch statements for multiple conditions.

Loops

  • for, for in, forEach, while, do while loops.
  • Use break to exit a loop and continue to skip an iteration.

Collections

  • List: Ordered collection, similar to arrays.
  • Set: Unordered collection of unique items.
  • Map: Collection of key-value pairs, similar to dictionaries.

Functions

  • Defined with returnType functionName(parameters) {}.
  • Supports arrow functions for concise syntax.
  • Anonymous functions (lambda) without a name.
  • Positional and named parameters in functions.

Object-Oriented Programming

Classes

  • Defined using class ClassName {}.
  • Constructor methods for initializing objects.
  • Named constructors for differentiated object creation.
  • Supports inheritance using extends.

Method Overriding

  • Override methods in subclass with @override annotation.

Getters and Setters

  • Define custom getters and setters using get and set keywords.

Exception Handling

  • Use try, catch, and finally for error handling.
  • throw keyword to raise exceptions.
  • Specific exceptions can be handled using on ExceptionType syntax.

Conclusion

  • Dart is robust for building cross-platform applications using Flutter.
  • Encouraged to explore more on Dart and Flutter.

Additional Resources

  • Visit Mahmoud Asan's YouTube channel for more tutorials.
  • Engage in the comment section for questions and discussions.