0% found this document useful (0 votes)
23 views3 pages

Dart Basics

Dart is an open-source programming language developed by Google, optimized for building user interfaces with the Flutter framework. It features static typing, object-oriented programming, null safety, and supports collections and asynchronous programming. Key concepts include variable declaration, functions, control flow statements, and classes with examples provided for each.

Uploaded by

tictactoe005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Dart Basics

Dart is an open-source programming language developed by Google, optimized for building user interfaces with the Flutter framework. It features static typing, object-oriented programming, null safety, and supports collections and asynchronous programming. Key concepts include variable declaration, functions, control flow statements, and classes with examples provided for each.

Uploaded by

tictactoe005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Dart Basics

1. Introduction to Dart

Dart is an open-source, general-purpose programming language developed by Google. It is

optimized for building user interfaces, especially for mobile, web, and desktop apps using the Flutter

framework.

2. Variables and Data Types

Dart is statically typed. You can use var, final, or const to declare variables.

Example:

var name = 'John';

int age = 25;

double height = 5.9;

bool isStudent = true;

final city = 'New York'; // Immutable variable

const PI = 3.14; // Compile-time constant

3. Functions

Functions in Dart are objects and can be assigned to variables or passed as parameters.

Example:

int add(int a, int b) {

return a + b;

4. Control Flow
Dart supports standard control flow statements like if-else, switch, for, while, and do-while loops.

Example:

if (age > 18) {

print("Adult");

} else {

print("Minor");

5. Classes and Objects

Dart is an object-oriented language with classes and single inheritance.

Example:

class Person {

String name;

int age;

Person(this.name, this.age);

void introduce() {

print("Hi, I am $name and I am $age years old.");

6. Null Safety

Dart uses sound null safety to eliminate null reference exceptions.


Example:

String? name; // Can be null

String fullName = 'John Doe'; // Cannot be null

7. Collections

Dart provides List, Set, and Map for collections.

Example:

List<int> numbers = [1, 2, 3];

Set<String> fruits = {'apple', 'banana'};

Map<String, String> capitals = {'USA': 'Washington, D.C.'};

8. Asynchronous Programming

Dart supports async-await for handling asynchronous operations.

Example:

Future<void> fetchData() async {

await Future.delayed(Duration(seconds: 2));

print("Data fetched");

You might also like