What is Dart?
Dart is a client-optimized programming language developed by Google. It is designed for building fast, scalable applications across multiple platforms, including mobile, web, desktop, and server. Dart is the primary language used for Flutter, Google's UI toolkit for building natively compiled applications.
Why Learn Dart?
Dart is easy to learn, especially if you have experience with languages like Java, JavaScript, or C#. It offers features like strong typing, null safety, async/await support, and a rich set of core libraries. With Dart, you can build high-performance apps using Flutter, write server-side code, and even create command-line tools.
Your First Dart Program
Every Dart program starts with the main() function. The print() function outputs text to the console.
Variables and Data Types
Dart is a statically typed language but also supports type inference via var. Common data types include:
- int – integer numbers
- double – floating-point numbers
- String – text
- bool – boolean values (true/false)
- List – ordered collection of objects
- Map – key-value pairs
Control Flow
Dart supports standard control flow statements:
Functions
Functions are first-class citizens in Dart. You can define functions with or without return types, and even pass functions as parameters.
Null Safety
Dart supports sound null safety, meaning variables cannot contain null unless you explicitly allow it. This prevents null reference errors. Use ? after a type to make it nullable, and use ! to assert non-null.
Classes and Objects
Dart is an object-oriented language. Classes define blueprints for objects.
Async Programming
Dart provides Future and async/await for asynchronous programming, making it easy to handle tasks like network requests or file I/O.
Key Takeaways
- Dart is a modern, client‑optimized language.
- It supports both JIT and AOT compilation.
- Strong typing with type inference and null safety.
- Object‑oriented with classes and mixins.
- Excellent for Flutter development.