Chapter 1: Introduction to Dart
Dart is a programming language developed by Google, used for building web, server,
and mobile applications. Dart emphasizes safety, speed, and developer productivity.
It supports object-oriented programming (OOP) concepts.
Chapter 2: Variables and Data Types
Variables store data in memory. Dart supports several types:
- int: integers
- double: floating point numbers
- String: text
- bool: true/false
- dynamic: any type
Declaring variables can be done using 'var', explicit types, or 'final'/'const' for
constants.
Chapter 3: Functions
Functions are blocks of code that perform tasks. Syntax:
void sayHello(String name) {
print("Hello, $name");
}
Functions can return values, accept parameters, and be assigned to variables.
Chapter 4: Object-Oriented Programming
OOP is a paradigm based on objects, which encapsulate data and behavior.
- Class: blueprint for objects
- Object: instance of a class
- Constructor: initializes objects
- Methods: functions inside classes
- Properties: variables inside classes
Chapter 5: Encapsulation
Encapsulation hides the internal state of an object. Access modifiers:
- public: accessible everywhere
- private: starts with '_', accessible only inside the class
Example:
class BankAccount {
int _balance;
BankAccount(this._balance);
void deposit(int amount) {
_balance += amount;
}
}
Chapter 6: Inheritance
Inheritance allows a class to derive properties and methods from another.
class Animal {
void speak() {
print("Some sound");
}
}
class Dog extends Animal {
@override
void speak() {
print("Woof");
}
}
Chapter 7: Polymorphism
Polymorphism allows objects to be treated as instances of their parent class.
List<Animal> animals = [Dog(), Animal()];
for (var a in animals) {
[Link]();
}
Chapter 8: Abstract Classes and Interfaces
Abstract classes define contracts that child classes must implement.
interface Printable {
void printDetails();
}
Chapter 9: Mixins
Mixins allow code reuse in multiple class hierarchies.
mixin Logger {
void log(String message) {
print("Log: $message");
}
}
Chapter 10: Generics
Generics provide type safety while keeping code flexible.
class Box<T> {
T value;
Box([Link]);
}
Chapter 11: Asynchronous Programming
Futures and Streams are used for async tasks.
Future<void> fetchData() async {
await [Link](Duration(seconds: 1));
print("Data fetched");
}
Chapter 12: Conclusion
Mastering Dart and OOP concepts is key to building modern apps efficiently.
Practice, projects, and reviewing examples help solidify understanding.