💻
Gürkan Fikret Günak - Personal
  • 👨‍💻About me
    • 🌊Journey
  • 🎯Dart
    • 🔬What's Dart Algorithms?
    • 🔬What's Dart Structures?
    • 🧮#01 Algorithm Guidance: Implementing Calculation Algorithms
    • 🧮#02 Algorithm Guidance: Two Sum
  • 📄Guidances
    • Flutter MVVM Guidance
    • Dart Programming Guidance
    • E-Commerce Use Cases
    • E-Commerce Applications
    • Flutter App Color Palette Usage Guidance
    • Flutter Custom AppBar Usage Guidance
    • Flutter Network Image Cache Usage Guidance
    • Flutter Project Bitbucket SSH Guidance
    • Flutter Project GitHub SSH Guidance
    • Flutter SliverAppBar Usage Guidance
    • The Importance of BuildContext in Flutter Tests Guidance
    • Internship Basic Guidance v0.1.0
    • The Importance of Type Casting in Flutter
    • Effective and Detailed Pull Request Guide
    • Flutter Naming Conventions Guidance
    • Flutter Widget Guidance
    • Semantic Commit Guidance
    • Being Part of a Mobile Software Team and Working on a Shared Architecture
    • Understanding Deep Links for Any Development Platform
    • The Journey of a Developer: Stories of Becoming Junior, Middle, and Senior Developer
    • Becoming a Team Leader: Growing in Sync with Your Team
    • Why IP Changes Are Important for Mobile Applications in Flutter
    • Why Your Growing Mobile Team Needs CI/CD and How to Build a Winning Strategy
    • Dart in 2024: 20 Features You Need to Know With Code Examples and Scenarios
    • Remote Theme Management with API (JSON): Implementing a Helper in Flutter SDK
    • Understanding and Implementing Force Upgrade in Your Flutter Project
    • Life Lessons from the Bald Eagle: A Metaphor for Growth, Change, and Leadership
    • The Beauty of Imperfection: Why Today Doesn’t Need to Be Perfect
    • # The Reverse Curve of Productivity: When Social Cohesion in Software Teams Starts to Hurt **How str
    • 📱 Mobil Uygulamalarda GraphQL Tercihi: Bakım ve Maliyet Etkiler
    • 📉 Türkiye’de Yazılım Projelerinde Süreç Yönetimi ve Ekonomik Kayıp: Bir Bekâ Sorunu mu?
  • 📹VIDEOS
    • Introduction to Flutter Boilerplate! ( Turkish )
    • Flutter APIs effective using ( English )
    • Understand to SDK ( English )
  • Links
    • 💼 | Linkedin
    • 🆇 | x.com
    • 📧 | Mail me
Powered by GitBook
On this page
  • 1. Introduction and Basics
  • What is Dart?
  • Features of Dart
  • Applications of Dart
  • 2. Environment and Setup
  • Dart Installation
  • Dart Development Environments
  • Your First Dart Application
  • 3. Basic Syntax and Data Types
  • Variables and Data Types
  • Maps and Collections
  • 4. Control Flow and Loops
  • if-else Statements
  • switch-case Statements
  • for Loops
  • while and do-while Loops
  • 5. Functions
  • Function Definition and Invocation
  • Parameters and Arguments
  • Nested Functions
  • Anonymous Functions
  • 6. Object-Oriented Programming (OOP)
  • Classes and Objects
  • Constructor Methods
  • Inheritance and Subclasses
  • Encapsulation
  • 7. Collections
  • Lists
  • Maps
  • 8. Error Handling
  • Exceptions
  • Debugging
  • Real-Life Scenario: Banking Application
  1. Guidances

Dart Programming Guidance

Welcome to the Dart Programming Guidance. This Guidance aims to provide step-by-step explanations and code examples for those interested in learning the Dart programming language. Below, you will find essential topics to get started with Dart programming.

1. Introduction and Basics

What is Dart?

Dart is an open-source programming language developed by Google. It can be used for both web and mobile application development.

Features of Dart

  • Supports object-oriented programming.

  • Has a static type system, where variable types are fixed.

  • Includes a fast virtual machine.

Applications of Dart

  • Developing mobile applications with the Flutter framework.

  • Building web applications.

  • Creating server-side applications.

2. Environment and Setup

Dart Installation

To install Dart on your computer, follow these steps:

  1. Follow the installation steps to install Dart on your computer.

Dart Development Environments

  • You can use Dart in popular IDEs like VS Code, Android Studio.

  • You can also develop Dart code using the dart command from the terminal.

Your First Dart Application

An example "Hello World" application:

void main() {
  print("Hello, World!");
}

This code snippet prints "Hello, World!" to the screen.

3. Basic Syntax and Data Types

Variables and Data Types

In Dart, variables are associated with a specific data type. Examples:

int number = 42;
String name = "John";
bool isTrue = true;

Adding an item to a list:

fruits.add("Strawberry");

Getting the length of a list:

int length = fruits.length;

Maps and Collections

Maps are used to store key-value pairs:

Map<String, int> ages = {
  "John": 25,
  "Jane": 30,
  "Alice": 28,
};

Adding a new key-value pair:

ages["Bob"] = 22;

Getting the value for a specific key:

int age = ages["John"];

4. Control Flow and Loops

if-else Statements

Using conditional statements to execute code based on conditions:

if (condition) {
  // Execute this block if the condition is true.
} else {
  // Execute this block if the condition is false.
}

switch-case Statements

Using switch-case to handle multiple conditions:

switch (variable) {
  case value1:
    // Code for value1.
    break;
  case value2:
    // Code for value2.
    break;
  default:
    // Code for other cases.
}

for Loops

Using for loops to iterate over a range of values:

for (int i = 0; i < 5; i++) {
  print("Loop iteration: $i");
}

while and do-while Loops

Using while and do-while loops to repeat actions based on conditions:

while (condition) {
  // Execute this block as long as the condition is true.
}

do {
  // Execute this block at least once, then check the condition.
} while (condition);

5. Functions

Function Definition and Invocation

Functions are blocks of code that perform specific tasks. Defining and invoking functions:

void greet() {
  print("Hello!");
}

// Invoking the function:
greet();

Parameters and Arguments

Passing data to functions using parameters and arguments:

void sayHello(String name) {
  print("Hello, $name!");
}

// Calling the function with an argument:
sayHello("John");

Nested Functions

Defining functions within functions:

void outerFunction() {
  void innerFunction() {
    print("Inner function executed");
  }

  print("Outer function executed");
  innerFunction();
}

outerFunction();

Anonymous Functions

Using anonymous functions for inline operations:

var add = (int x, int y) {
  return x + y;
};

print(add(5, 3)); // 8

6. Object-Oriented Programming (OOP)

Classes and Objects

In Dart, classes are used to create objects. An example of a student class:

class Student {
  String name;
  int age;

  Student(this.name, this.age);

  void greet() {
    print("Hello, I'm $name, $age years old.");
  }
}

void main() {
  var student = Student("John", 25);
  student.greet(); // Hello, I'm John, 25 years old.
}

Constructor Methods

Special methods that are called when an object is created:

class Car {
  String brand;
  String model;

  Car(this.brand, this.model);

  void showInfo() {
    print("Brand: $brand, Model: $model");
  }
}

void main() {
  var car = Car("Toyota", "Corolla");
  car.showInfo(); // Brand: Toyota, Model: Corolla
}

Inheritance and Subclasses

Using inheritance to reuse properties and methods from another class:

class Product {
  String name;
  double price;

  Product(this.name, this.price);

  void showInfo() {
    print("Product: $name, Price: $price");
  }
}

class Phone extends Product {
  String brand;

  Phone

(String name, double price, this.brand) : super(name, price);

  @override
  void showInfo() {
    print("Phone: $brand $name, Price: $price");
  }
}

void main() {
  var phone = Phone("iPhone", 800, "Apple");
  phone.showInfo(); // Phone: Apple iPhone, Price: 800
}

Encapsulation

Controlling access to class properties:

class Person {
  String _name; // Property is hidden using an underscore.
  int _age;

  Person(this._name, this._age);

  String get name => _name; // Only read access.
  set age(int newAge) {
    if (newAge > 0) {
      _age = newAge;
    }
  }

  void showInfo() {
    print("Name: $_name, Age: $_age");
  }
}

void main() {
  var person = Person("John", 25);
  person.showInfo(); // Name: John, Age: 25
  print(person.name);   // John
  person.age = 30;
  person.showInfo(); // Name: John, Age: 30
}

7. Collections

Lists

Using lists to store and manage multiple items:

List<int> numbers = [1, 2, 3, 4, 5];
List<String> fruits = ["Apple", "Orange", "Banana"];

Adding an item to a list:

fruits.add("Strawberry");

Getting the length of a list:

int length = fruits.length;

Maps

Using maps to store key-value pairs:

Map<String, int> ages = {
  "John": 25,
  "Jane": 30,
  "Alice": 28,
};

Adding a new key-value pair:

ages["Bob"] = 22;

Getting the value for a specific key:

int age = ages["John"];

8. Error Handling

Exceptions

Managing errors using the exception mechanism in Dart:

try {
  // Code that might throw an exception
} catch (e) {
  // Code executed when an exception is caught
} finally {
  // Code executed regardless of whether an exception occurred or not
}

Debugging

Using print statements for debugging purposes:

print("This is a debugging message.");

Additionally, you can use the debugger statement to add breakpoints for advanced debugging.


Real-Life Scenario: Banking Application

Imagine you're building a banking application using Dart. Here's a simplified example of how you might structure your code for managing customer accounts:

class Customer {
  String name;
  double balance;

  Customer(this.name, this.balance);

  void deposit(double amount) {
    balance += amount;
    print("$name deposited $$amount. New balance: $$balance");
  }

  void withdraw(double amount) {
    if (balance >= amount) {
      balance -= amount;
      print("$name withdrew $$amount. New balance: $$balance");
    } else {
      print("Insufficient funds for $name.");
    }
  }

  void displayBalance() {
    print("Current balance for $name: $$balance");
  }
}

void main() {
  var customer1 = Customer("John Doe", 1000);
  var customer2 = Customer("Jane Smith", 500);

  customer1.deposit(300);
  customer1.withdraw(200);
  customer1.displayBalance();

  customer2.withdraw(700);
  customer2.displayBalance();
}

In this scenario, the Customer class represents bank customers with their names and account balances. The methods within the class allow customers to deposit, withdraw, and check their account balances.


This concludes our Dart Programming Guidance. You have covered essential topics and gained insights into real-life scenarios. Feel free to expand upon this Guidance and explore more advanced topics as you continue your journey in Dart programming. Happy coding!

PreviousFlutter MVVM GuidanceNextE-Commerce Use Cases

Download the Dart SDK from the and initiate the installation.

📄
official website