learning_dart_with_code_examples
learning_dart_with_code_examples
Introduction to Dart:
- Dart is a programming language designed for client-side development, especially for building
- In this guide, we'll walk through Dart concepts with examples to help you understand how to use
them effectively.
Dart has several data types such as int, double, String, bool, and more.
Example:
```dart
```
Use 'final' for runtime constants and 'const' for compile-time constants.
Example:
```dart
final String city = "Cape Town";
```
3. Operators:
Example:
```dart
int x = 10, y = 5;
```
4. Control Flow:
Example:
```dart
print("Adult");
} else {
print("Minor");
```
Functions in Dart:
1. Declaring Functions:
Example:
```dart
print("Hello, $name!");
```
Example:
```dart
return a + b;
```
3. Arrow Functions:
Example:
```dart
```
Object-Oriented Programming (OOP) in Dart:
Example:
```dart
class Person {
String name;
int age;
Person(this.name, this.age);
void introduce() {
```
Example:
```dart
class Animal {
void speak() {
print("Animal speaks");
@override
void speak() {
print("Dog barks");
```
Dart Collections:
1. Lists:
Example:
```dart
fruits.add("Mango");
```
2. Maps:
Example:
```dart
```
Asynchronous Programming:
Dart allows you to write asynchronous code using Futures, async, and await.
Example:
```dart
```
Error Handling:
1. Try, Catch, Finally:
Example:
```dart
try {
int result = 10 ~/ 0;
} catch (e) {
} finally {
print("Execution completed");
```
1. Generics:
Example:
```dart
class Box<T> {
T value;
Box(this.value);
```
2. Extension Methods:
Dart allows you to extend classes without modifying their original code.
Example:
```dart
return this.split('').reversed.join('');
```