← Dart EnglishChapter 01 of 13

Introduction to Dart

## Learning Objectives - Understand Dart history and platform - Set up Dart development environment - Write and run your first Dart program - Understand Dart syntax basics ## What is Dart? Dart is a client-optimized programming language developed by Google, first released in 2011. It is designed for building mobile, desktop, and web applications. ```dart void main() { print('Hello, World!'); } ``` ## Dart Platform ### Key Features - **Optimized for UI Development** - Built-in animation and graphics libraries - **Productive Development** - Hot reload for fast development cycles - **Fast Performance** - Compiles to native code or JavaScript - **Strong Typing** - Type-safe with type inference - **Null Safety** - Prevents null reference errors at compile time ### Platform Components | Component | Description | |-----------|-------------| | Dart VM | Runs Dart code natively | | Dart Compiler | Compiles to native code or JavaScript | | Dart SDK | Tools and libraries for development | | Flutter SDK | UI framework built on Dart | ## Installing Dart ### Download Get Dart SDK from ### macOS/Linux ```bash brew install dart ``` ### Windows ```powershell winget install dart-sdk ``` ### Verify Installation ```bash dart --version ``` ## Your First Program ### File: hello.dart ```dart void main() { print('Hello, World!'); } ``` ### Run ```bash dart hello.dart ``` ## Dart Program Structure ```dart void main() { // Entry point // Statements go here } ``` ### Components 1. **main function**: Entry point of every Dart program 2. **Statements**: Commands to execute 3. **Semicolons**: Required to end statements ## Comments ```dart // Single-line comment /* * Multi-line comment */ ``` ## Comments (Documentation) ```dart /// Documentation comment (single line) /** * Documentation comment * (multi-line) */ ``` ## System Output ```dart // Print with newline print('Hello'); // Print multiple values print('Name: $name, Age: $age'); // Print expressions print('Sum: ${a + b}'); ``` ## Command Line Arguments ### hello.dart ```dart void main(List args) { if (args.isNotEmpty) { print('Hello, ${args[0]}!'); } else { print('Hello, World!'); } } ``` ```bash dart hello.dart Alice # Output: Hello, Alice! ``` ## Variables in Dart ```dart void main() { var name = 'Alice'; // Type inferred String greeting = 'Hello'; // Explicit type int age = 30; // Explicit type print('$greeting, $name! You are $age.'); } ``` ## Data Types ```dart void main() { int count = 42; double price = 19.99; String text = 'Dart'; bool isActive = true; print('Count: $count, Price: $price'); print('Text: $text, Active: $isActive'); } ``` ## IDEs ### Popular IDEs - VS Code (recommended with Dart extension) - Android Studio / IntelliJ IDEA (with Dart plugin) - DartPad (online at dartpad.dev) ## Dart Versions ```bash dart --version # Check installed version ``` | Version | Year | Feature | |---------|------|---------| | Dart 2 | 2018 | Strong mode, sound null safety | | Dart 2.12 | 2021 | Null safety (stable) | | Dart 3 | 2023 | Records, patterns, class modifiers | ## Summary - Dart is a client-optimized language by Google - Every Dart program has a `main()` function - `dart` command runs `.dart` files directly - `var` for type inference, explicit types also supported - Comments: `//`, `/* */`, `///`

Comments

Comments powered by Giscus

To enable comments, add your Giscus embed code here.

Learn more about Giscus →