Learn Technology in Simple English
Dart is a modern programming language developed by Google. It is designed for building fast applications across different platforms.
Dart is especially well known because it is the programming language used by Flutter for creating applications.
With Dart and Flutter, developers can create applications for Android, iOS, web, desktop, and other supported platforms.
Dart was developed by Google and was introduced in 2011.
The language has continued to evolve over time and has become closely connected with Google's Flutter framework.
Dart is important because it provides:
Dart can be used for:
However, Dart is most commonly associated with Flutter application development.
Dart programs can be compiled and executed in different ways depending on the target platform and development environment.
For Flutter applications, Dart can be compiled into efficient native code for supported platforms.
A simple Dart program looks like this:
void main() {
print("Hello, world!");
}
The main() function is the starting point of a basic Dart program.
Variables store information that a program can use.
void main() {
var name = "Ahmed";
var age = 20;
print(name);
print(age);
}
The var keyword allows Dart to determine a variable's type from its initial value.
var name = "Ahmed";
var age = 20;
Dart provides final and const for values that should not be reassigned.
final name = "Ahmed";
const maxScore = 100;
A final variable is assigned once, while a const value must be a compile-time constant.
| Type | Example |
|---|---|
| String | "Hello" |
| int | 25 |
| double | 25.5 |
| bool | true |
| List | [1, 2, 3] |
| Map | {"name": "Ahmed"} |
Strings are used to store text.
String firstName = "Ahmed";
String lastName = "Ali";
String fullName = "$firstName $lastName";
void main() {
print(fullName);
}
Dart supports mathematical, comparison, and logical operators.
void main() {
int a = 10;
int b = 5;
print(a + b);
print(a - b);
print(a * b);
print(a / b);
}
Conditional statements allow programs to make decisions.
void main() {
int age = 20;
if (age >= 18) {
print("Adult");
} else {
print("Minor");
}
}
Multiple conditions can be checked using else if.
void main() {
int score = 75;
if (score >= 80) {
print("Excellent");
} else if (score >= 60) {
print("Good");
} else {
print("Keep practicing");
}
}
A switch statement can be used when a value has several possible cases.
void main() {
String day = "Monday";
switch (day) {
case "Monday":
print("Start of the week");
break;
case "Friday":
print("End of the work week");
break;
default:
print("Another day");
}
}
A for loop repeats code for a sequence of values.
void main() {
for (int i = 1; i <= 5; i++) {
print(i);
}
}
void main() {
int number = 1;
while (number <= 5) {
print(number);
number++;
}
}
Functions are reusable blocks of code.
void greet() {
print("Hello!");
}
void main() {
greet();
}
Functions can receive values through parameters.
void greet(String name) {
print("Hello, $name!");
}
void main() {
greet("Ahmed");
}
A function can calculate something and return a result.
int add(int a, int b) {
return a + b;
}
void main() {
int result = add(5, 3);
print(result);
}
Short functions can sometimes be written using arrow syntax.
int square(int number) => number * number;
void main() {
print(square(5));
}
A List stores multiple values in an ordered collection.
void main() {
List<int> numbers = [10, 20, 30, 40];
print(numbers[0]);
}
void main() {
List<String> names = ["Ahmed", "Ali"];
names.add("Umar");
print(names);
}
A Map stores information using key-value pairs.
void main() {
Map<String, dynamic> user = {
"name": "Ahmed",
"age": 20
};
print(user["name"]);
}
A Set stores unique values.
void main() {
Set<int> numbers = {1, 2, 3, 3};
print(numbers);
}
Classes allow developers to create custom objects.
class User {
String name;
int age;
User(this.name, this.age);
}
void main() {
User user = User("Ahmed", 20);
print(user.name);
}
An object is an instance of a class.
void main() {
User user = User("Ahmed", 20);
print(user.name);
}
The object contains the data and behavior defined by its class. The example uses the User class defined in the previous section.
Constructors are used when creating objects.
class Car {
String brand;
Car(this.brand);
}
void main() {
Car car = Car("Toyota");
print(car.brand);
}
Dart supports inheritance, which allows one class to reuse functionality from another class.
class Animal {
void speak() {
print("Animal sound");
}
}
class Dog extends Animal {
void bark() {
print("Woof");
}
}
void main() {
Dog dog = Dog();
dog.speak();
dog.bark();
}
Abstract classes can define a common structure for other classes.
abstract class Animal {
void speak();
}
class Dog extends Animal {
@override
void speak() {
print("Woof");
}
}
void main() {
Dog dog = Dog();
dog.speak();
}
Null safety helps developers identify variables that can contain null and variables that are expected to always contain a value.
String name = "Ahmed";
String? nickname;
The question mark means that nickname can contain null.
void main() {
String? name;
name = "Ahmed";
print(name);
}
Before using nullable values where a non-null value is required, safely handle the possibility of null.
Dart provides operators that make working with nullable values easier.
void main() {
String? name;
print(name ?? "Unknown");
}
The ?? operator provides a fallback value when the value on the left is null.
Enums represent a fixed set of related values.
enum Direction {
north,
south,
east,
west
}
void main() {
Direction direction = Direction.north;
print(direction);
}
Asynchronous programming allows an application to perform operations that may take time without unnecessarily blocking other work.
This is useful when working with networks, files, databases, and other operations that may take time.
A Future represents a value that may become available later.
Future<String> getMessage() async {
return "Hello from the future";
}
void main() async {
print(await getMessage());
}
The async and await keywords make asynchronous code easier to read.
Future<String> getMessage() async {
return "Data loaded";
}
Future<void> loadData() async {
String message = await getMessage();
print(message);
}
Future<void> main() async {
await loadData();
}
A Stream can provide multiple values over time.
Streams are useful for events, live data, user interactions, and other situations where information arrives continuously.
Dart uses try, catch, and finally for handling errors.
void main() {
try {
int result = 10 ~/ 0;
print(result);
} catch (error) {
print("An error occurred");
}
}
DartPad is an online environment where developers can experiment with Dart code without installing a full development environment.
It can be useful for beginners who want to practice Dart syntax and small programs.
Flutter is Google's UI toolkit for building applications from a shared codebase.
Flutter uses Dart as its primary programming language.
With Flutter, developers can build applications for multiple platforms while sharing much of the application code.
Dart provides the programming language while Flutter provides the application UI framework and development tools.
Flutter developers use Dart to define application logic, data models, user interactions, and interface code.
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
home: Scaffold(
body: Center(
child: Text("Hello Flutter"),
),
),
),
);
}
Dart can be used to build Android applications through Flutter.
Flutter allows developers to create Android interfaces and application logic using Dart.
Dart can also be used to create iOS applications through Flutter.
This allows developers to share much of the application code between Android and iOS.
Flutter can target the web, allowing Dart-based Flutter applications to run in web environments.
Dart can also be compiled for web-related use cases.
Flutter supports desktop application development for supported desktop platforms.
This allows Dart developers to use Flutter to create graphical desktop applications.
Packages are reusable collections of Dart code that can add functionality to a project.
Packages can provide tools for networking, databases, authentication, UI components, utilities, and many other tasks.
The Dart and Flutter ecosystem has a package repository called pub.dev.
Developers can search for packages, read documentation, and add useful dependencies to their projects.
Flutter and Dart projects commonly use a file called pubspec.yaml.
This file can contain information about the project, dependencies, assets, and other configuration.
dependencies:
flutter:
sdk: flutter
Dart applications can communicate with APIs to retrieve or send data.
This is especially common in Flutter applications that connect to online services.
For example, a mobile app can request weather, sports, news, product, or user information from a remote API.
JSON is commonly used to exchange data between applications and APIs.
import 'dart:convert';
void main() {
String jsonText = '{"name":"Ahmed","age":20}';
Map<String, dynamic> data = jsonDecode(jsonText);
print(data["name"]);
}
Dart and Flutter applications can work with local or remote databases using suitable packages and services.
Applications can store information such as users, products, messages, settings, notes, and other data.
| Dart | JavaScript |
|---|---|
| Supports static typing and type inference | Commonly uses dynamic typing |
| Commonly used with Flutter | Commonly used for web development |
| Supports null safety in its type system | Uses a different type system |
| Can compile to different targets | Runs widely in browsers and other environments |
| Dart | Kotlin |
|---|---|
| Commonly used with Flutter | Commonly used with Android and JVM development |
| Supports multi-platform development through Flutter | Has a strong Android ecosystem |
| Uses Dart syntax | Uses Kotlin syntax |
| Supports null safety | Supports null safety |
Both languages are modern and strongly typed, but they are commonly used in different development ecosystems.
Dart is relatively approachable, but beginners may need time to understand some concepts.
Yes. Dart can be a good language for beginners, especially people who want to learn Flutter and build mobile applications.
The language has readable syntax, and many concepts can be learned gradually.
Good beginner projects include:
dynamic everywhere| Concept | Example |
|---|---|
| Variable | var age = 20; |
| String | String name = "Ahmed"; |
| Constant | const max = 100; |
| Function | void hello() {} |
| List | [1, 2, 3] |
| Map | {"name": "Ahmed"} |
| Nullable value | String? name; |
| Class | class User {} |
| Async function | Future<void> load() async {} |
print("Hello"); |
Yes. Dart is an open-source programming language.
No. Dart is a programming language, while Flutter is a framework and toolkit used to build applications.
Yes. Dart can be used to build Android applications through Flutter.
Yes. Flutter uses Dart to create applications that can target iOS.
Dart can be used for web-related development, and Flutter can target the web.
Learning the basics of Dart before starting Flutter is strongly helpful.
Dart has readable syntax and can be approachable for beginners. Advanced concepts such as asynchronous programming and generics require practice.
pub.dev is the package repository used by the Dart and Flutter ecosystem.
Dart is a modern programming language developed by Google and is best known as the main programming language used by Flutter.
It provides variables, functions, classes, null safety, asynchronous programming, collections, packages, and many other features needed to build modern applications.
For beginners interested in mobile application development, learning Dart is a useful step toward learning Flutter.
Start with basic Dart programming, practice with small projects, and then gradually move into Flutter and complete application development.