SlideShare a Scribd company logo
Dart Programming
Language
- Lim Phanith - 21 March 2023
Content Outline
I. Introduction
II. Variable
III. List and Mapping
IV. Control Flow
V. Function
VI. Classes
VII. Object-Oriented Programming
VIII. Asynchronous
IX. Practice
2
I. Introduction
Dart is a general purpose programming language developed by Google. You can
use it to develop web, server, desktop and mobile applications for iOS and
Android. It’s easy to learn (especially if you read this book) and also has great
tooling support.
3
II. Variables & Constants 🧮
int n1 = 10; stores integers (whole numbers), without decimals, such
as 123 or -123
double n2 = 12.23; stores floating point numbers, with decimals, such as
19.99 or -19.99
String n3 = 'myString'; stores text, such as "Hello World". String values are
surrounded by double quotes
bool n4 = true; stores values with two states: true or false
var n5 = 12; The var keyword says to Dart, “Use whatever type is
appropriate.”
dynamic n6 = '12112';
n5 = 12.12;
n5 = 12;
lets you assign any data type you like to your variable
num n7 = 12.5;
num n7 = 12;
store both an integer and floating-point value
const n10 = 10; constants when compile-time
final n11 = n1 + n2; constants when runtime
4
III. List and Mapping 🧮
void main() {
List<int> myList = [1, 3, 5, 1, 5, 8, 9];
myList.forEach((element) {
print(element);
});
myList.removeAt(5);
myList.sort();
}
void main() {
Map<String, dynamic> student = {
'id': 12323,
'name': 'Phanith',
'age': 20,
'address': '123 Main St',
'phone': '555-555-5555'
};
print(student['name']);
./Modify the student map to add a new key/value pair
student['name'] = 'John';
./forEach loop to print out all the key/value pairs
student.forEach((key, value) {
print('$key: $value');
});
./Remove the phone key/value pair
student.clear();
}
List
Mapping
5
IV. Control Flow 🕹
const animal = 'Fox';
if (animal == 'Cat' .| animal .= 'Dog') {
print('Animal is a house pet.');
} else {
print('Animal is not a house pet.');
}
If else statement
const trafficLight = 'yellow';
var command = '';
if (trafficLight .= 'red') {
command = 'Stop';
} else if (trafficLight .= 'yellow') {
command = 'Slow down';
} else if (trafficLight .= 'green') {
command = 'Go';
} else {
command = 'INVALID COLOR!';
}
print(command);
If else-if statement
6
IV. Control Flow 🕹
const number = 3;
switch (number) {
case 0:
print('zero');
break;
case 1:
print('one');
break;
case 2:
print('two');
break;
case 3:
print('three');
break;
case 4:
print('four');
break;
default:
print('something else');
}
switch statement Noted:
switch statement is usually faster than a series of
if-else statements when there are many cases to
check. This is because a switch statement uses a table
lookup to determine which case to execute, while a
series of if-else statements requires a linear search
through each condition until a match is found.
7
IV. Control Flow 🕹
While Loop
while (condition) {
./ loop code
}
Do-while Loop
do {
./ loop code
} while (condition)
for(Initialization; condition; incrdecr) {
./ loop body
}
For Loop
For-in Loop
List<int> myList = [1,2 ,1, 1, 4];
for(var num in myList){
print("item: $num");
}
List<int> myList = [3,3 ,3, 4];
myList.forEach((element) {
print("item: $element");
});
ForEach Loop
Noted:
forEach is that it is often faster and more efficient than
using a traditional for loop, especially for large collections.
This is because forEach uses an internal iterator that is
optimized for performance, while a traditional for loop
with an index variable may be slower due to the overhead
of incrementing and checking the index variable on each
iteration.
8
V. Function 󰥲
In programming, a function is a block of code that performs a specific task or set of tasks.
Functions can be thought of as small, self-contained units of code that can be reused
throughout a program.
9
V. Function 󰥲
int sum(int a, int b) .> a + b;
void main() {
int result = sum(5, 7);
}
Take parameters, Return values
void printMessage(String message) {
print(message);
}
void main() {
printMessage("Hello, world!");
}
Take parameters, No return values
No parameters, Return values
import 'dart:math';
int getRandomNumber() {
final random = Random();
return random.nextInt(10) + 1;
}
void main() {
int randomNum = getRandomNumber();
}
No parameters, No return values
void printList(List<int> numbers) {
for (final number in numbers) {
print(number);
}
}
void main() {
final List<int> numbers = [1, 2, 3, 4, 5];
printList(numbers);
}
10
VI. Nullability - Null Safety 📭
Null Safety in simple words means a variable cannot contain a ‘null’ value unless you
initialized with null to that variable. With null safety, all the runtime null-dereference
errors will now be shown in compile time.
final String msg1 = null; Error Null can’t be assigned to a variable
final String? msg2 = null; No error
11
VI. Nullability - Null Safety 📭
void crushMessage(String msg) {
print("MESSAGE: $msg");
}
void main() {
final String? name = "Hey, I'm a string!";
crushMessage(name); Error Null can’t be assigned to a variable
}
void crushMessage(String msg) {
print("MESSAGE: $msg");
}
void main() {
final String? name = "Hey, I'm a string!";
crushMessage(name!);
}
Bug
Solution
12
VI. Enumeration 🥇🥈🥉
In Dart, enum is a special data type that represents a group of related constants. An enum
declaration consists of a list of named constant values, called enum members.
Window MacOS Linux
13
VI. Enumeration 🥇🥈🥉
enum CustomerType {
regular,
premium,
vip
}
void main() {
CustomerType customerType = CustomerType.premium;
switch (customerType) {
case CustomerType.regular:
print('This is a regular customer.');
break;
case CustomerType.premium:
print('This is a premium customer.');
break;
case CustomerType.vip:
print('This is a VIP customer.');
break;
}
}
14
V. CLASSES 󰥍
In Dart, a class is a blueprint for creating objects that have similar characteristics and behavior.
It defines a set of attributes (also known as properties or instance variables) and methods that
can be used to manipulate those attributes.
15
IV. CLASSES 󰥍
enum Gender{Male, Female}
class Person {
final String name;
final int age;
final Gender gender;
final String? occupation;
./ constructor
Person({
required this.name,
required this.age,
required this.gender,
this.occupation,
});
./Method or Behavior
void walk(){}
void speak(){}
void eat(){}
}
void main() {
Person phanith = Person(name: "Phanith", age: 20, gender: Gender.Male, occupation: "Student");
}
Property
Constructor
Method
16
VII. Object-Oriented Programming 🔥
Dart is an object-oriented programming language, and it supports all the concepts of
object-oriented programming such as classes, object, inheritance, mixin, and abstract classes. As
the name suggests, it focuses on the object and objects are the real-life entities. The
Object-oriented programming approach is used to implement the concept like polymorphism,
data-hiding, etc. The main goal of oops is to reduce programming complexity and do several tasks
simultaneously
17
Encapsulation
Encapsulation is one of the important concepts of object-oriented programming. Before
learning about dart encapsulation, you should have a basic understanding of the class and object
in dart. Encapsulation means hiding data within a library, preventing it from outside factors. It
helps you control your program and prevent it from becoming too complicated
18
Encapsulation
class Student {
String _name;
int _age;
String _address;
String _phone;
Student(this._name, this._age, this._address, this._phone);
./ Getters
String get name .> _name;
int get age .> _age;
String get address .> _address;
String get phone .> _phone;
./ Setters
set name(String name) .> this._name = name;
set age(int age) .> _age = age;
set address(String address) .> _address = address;
set phone(String phone) .> _phone = phone;
@override
String toString() {
return 'Student: $_name, $_age, $_address, $_phone';
}
}
void main() {
Student student = Student('John', 20, '123 Main St', '555-555-5555');
print(student.toString());
}
19
Inheritance
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a new
class, called the subclass or derived class, to be based on an existing class, called the base class
or superclass. The subclass inherits properties and methods from the base class, and can also
add new properties and methods or modify the behavior of the inherited ones
20
Inheritance
class Animal {
void eat() {
print('The animal is eating');
}
}
class Dog extends Animal {
void bark() {
print('The dog is barking');
}
}
void main() {
Dog myDog = Dog();
myDog.eat();
myDog.bark();
}
21
Polymorphism
Polymorphism is a concept in object-oriented programming that allows objects of different
classes to be treated as if they were of the same type. In other words, it is the ability of an object
to take on many forms.
22
Polymorphism
class Animal {
void makeSound() {
print('The animal makes a sound');
}
}
class Dog extends Animal {
void makeSound() {
print('The dog barks');
}
}
class Cat extends Animal {
void makeSound() {
print('The cat meows');
}
}
void main() {
Animal animal = new Animal();
Animal dog = new Dog();
Animal cat = new Cat();
animal.makeSound();
dog.makeSound();
cat.makeSound();
}
23
Abstract
In programming, the term "abstract" refers to the concept of defining common interface or
behavior without implementing it in detail. In object-oriented programming, an abstract class is
a class that cannot be instantiated directly, but can be used as a base class for other classes.
24
Abstract
abstract class Shape {
double area();
}
class Circle extends Shape {
double radius;
Circle(this.radius);
double area() {
return 3.14 * radius * radius;
}
}
class Rectangle extends Shape {
double width, height;
Rectangle(this.width, this.height);
double area() {
return width * height;
}
}
void main() {
Circle circle = Circle(5);
Rectangle rectangle = Rectangle(5, 10);
print(circle.area());
print(rectangle.area());
} 25
Interface
In programming, an interface is a specification of a set of methods and properties that a class
must implement. An interface does not provide any implementation details, but rather defines a
contract or agreement between different classes that share a common set of behaviors.
26
Interface
class CountryRule {
void noGun() {
print('No gun');
}
}
class SchoolRule {
void noLongHair() {
print('No long hair');
}
}
class Student implements CountryRule, SchoolRule {
@override
void noGun() {
print('No gun');
}
@override
void noLongHair() {
print('No long hair');
}
}
void main() {
Student student = Student();
student.noGun();
student.noLongHair();
}
27
I. Asynchronous
Asynchronous programming is a programming paradigm that allows tasks to be executed
concurrently and independently of each other, without having to wait for each task to complete
before moving on to the next one. In other words, it enables a program to perform multiple
operations at the same time, which can greatly improve its performance and responsiveness.
28
VIII. Asynchronous
Future<void> printNumbers() async {
print('Starting to print numbers...');
./ wait for 1 second before printing each number
for (int i = 1; i .= 5; i.+) {
await Future.delayed(Duration(seconds: 1));
print(i);
}
print('Finished printing numbers.');
}
void main() {
printNumbers();
print('Continuing to execute other tasks...');
}
29
Practice
Exercise 01: Write a program to sum the following series:
Exercise 02: Accept 10 integers from the user to store them in an array, and display the average of the positive and negative
numbers.
Exercise 03: Write function convert decimal to binary.
Exercise 04: (Simulation firing a gun) You progress to the third game of the Squid Game. For this game, six players will play
together. Five bullets are put into a gun's round barrel which can hold up to six bullets.
A staff from the game will start pointing the gun at the first player and firing the gun. If no bullet is fired, the player survives,
otherwise, the player gets shot and die. The staff will do the same to all players one by one. Note that the staff will roll the barrel
before each shooting. Which turn (1st to 6th) would you choose to increase your chance of survival? Write a program to
simulate this gun shooting game one thousand rounds, and display the number of each player getting shot based on the turn
they take to get shot.
30
THANK YOU
31

More Related Content

PDF
Mobile development with Flutter
PDF
Dart workshop
PDF
Flutter tutorial for Beginner Step by Step
PDF
basics dart.pdf
PPTX
Flutter Introduction and Architecture
PDF
Basic Introduction Flutter Framework.pdf
PPTX
GDSC Flutter Forward Workshop.pptx
PDF
Animations in Flutter
Mobile development with Flutter
Dart workshop
Flutter tutorial for Beginner Step by Step
basics dart.pdf
Flutter Introduction and Architecture
Basic Introduction Flutter Framework.pdf
GDSC Flutter Forward Workshop.pptx
Animations in Flutter

What's hot (20)

PDF
Pune Flutter Presents - Flutter 101
PDF
Introduction to flutter
PDF
Developing Cross platform apps in flutter (Android, iOS, Web)
PPTX
Dart programming language
PPTX
Dart ppt
PDF
Build beautiful native apps in record time with flutter
PPTX
Flutter workshop
PPT
Native, Web or Hybrid Mobile App Development?
PDF
Events and Listeners in Android
PDF
[Alexandria Devfest] the magic of flutter
PPTX
Mobile Application Development: Hybrid, Native and Mobile Web Apps
PDF
Build responsive applications with google flutter
PPT
iOS Introduction For Very Beginners
PDF
Android Networking
PPTX
Introduction to Flutter
PPTX
1 java programming- introduction
PDF
JavaScript - Chapter 8 - Objects
PDF
Asynchronous JavaScript Programming
PPTX
Dart presentation
Pune Flutter Presents - Flutter 101
Introduction to flutter
Developing Cross platform apps in flutter (Android, iOS, Web)
Dart programming language
Dart ppt
Build beautiful native apps in record time with flutter
Flutter workshop
Native, Web or Hybrid Mobile App Development?
Events and Listeners in Android
[Alexandria Devfest] the magic of flutter
Mobile Application Development: Hybrid, Native and Mobile Web Apps
Build responsive applications with google flutter
iOS Introduction For Very Beginners
Android Networking
Introduction to Flutter
1 java programming- introduction
JavaScript - Chapter 8 - Objects
Asynchronous JavaScript Programming
Dart presentation
Ad

Similar to Basic Dart Programming Language 2023.pdf (20)

PPTX
App_development55555555555555555555.pptx
PPTX
Chapter 2 Flutter Basics Lecture 1.pptx
PPTX
pembelajaran tentang dart dalam bahasa inggris
PPTX
advance-dart.pptx
PDF
Flutter_CharbelAkiki.pdf
PDF
Flutter Festival IIT Goa: Session 1
PPTX
1-introduction-to-dart-programming.pptx
PPTX
Dart 1 In Dart, a programming language developed by Google, data types are us...
PPTX
Presentaion on Dart and Flutter Development.pptx
PDF
Glancing essential features of Dart, before stepping into Flutter
PPTX
introduction to dart --- Section two - 2.pptx
PDF
Introduction to Dart
PPTX
Dart PPT.pptx
PPTX
Mobile Application Development class 002
PPTX
Mobile Applications Development class 02 ntroduction to Drat
PDF
Language tour of dart
PDF
GDSC-FlutterBasics.pdf
PPT
Basic Java Concept - Practical Oriented Methodologies
PPTX
Dart structured web apps
PPTX
Dart Programming.pptx
App_development55555555555555555555.pptx
Chapter 2 Flutter Basics Lecture 1.pptx
pembelajaran tentang dart dalam bahasa inggris
advance-dart.pptx
Flutter_CharbelAkiki.pdf
Flutter Festival IIT Goa: Session 1
1-introduction-to-dart-programming.pptx
Dart 1 In Dart, a programming language developed by Google, data types are us...
Presentaion on Dart and Flutter Development.pptx
Glancing essential features of Dart, before stepping into Flutter
introduction to dart --- Section two - 2.pptx
Introduction to Dart
Dart PPT.pptx
Mobile Application Development class 002
Mobile Applications Development class 02 ntroduction to Drat
Language tour of dart
GDSC-FlutterBasics.pdf
Basic Java Concept - Practical Oriented Methodologies
Dart structured web apps
Dart Programming.pptx
Ad

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
sap open course for s4hana steps from ECC to s4
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Assigned Numbers - 2025 - Bluetooth® Document
sap open course for s4hana steps from ECC to s4
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Basic Dart Programming Language 2023.pdf

  • 1. Dart Programming Language - Lim Phanith - 21 March 2023
  • 2. Content Outline I. Introduction II. Variable III. List and Mapping IV. Control Flow V. Function VI. Classes VII. Object-Oriented Programming VIII. Asynchronous IX. Practice 2
  • 3. I. Introduction Dart is a general purpose programming language developed by Google. You can use it to develop web, server, desktop and mobile applications for iOS and Android. It’s easy to learn (especially if you read this book) and also has great tooling support. 3
  • 4. II. Variables & Constants 🧮 int n1 = 10; stores integers (whole numbers), without decimals, such as 123 or -123 double n2 = 12.23; stores floating point numbers, with decimals, such as 19.99 or -19.99 String n3 = 'myString'; stores text, such as "Hello World". String values are surrounded by double quotes bool n4 = true; stores values with two states: true or false var n5 = 12; The var keyword says to Dart, “Use whatever type is appropriate.” dynamic n6 = '12112'; n5 = 12.12; n5 = 12; lets you assign any data type you like to your variable num n7 = 12.5; num n7 = 12; store both an integer and floating-point value const n10 = 10; constants when compile-time final n11 = n1 + n2; constants when runtime 4
  • 5. III. List and Mapping 🧮 void main() { List<int> myList = [1, 3, 5, 1, 5, 8, 9]; myList.forEach((element) { print(element); }); myList.removeAt(5); myList.sort(); } void main() { Map<String, dynamic> student = { 'id': 12323, 'name': 'Phanith', 'age': 20, 'address': '123 Main St', 'phone': '555-555-5555' }; print(student['name']); ./Modify the student map to add a new key/value pair student['name'] = 'John'; ./forEach loop to print out all the key/value pairs student.forEach((key, value) { print('$key: $value'); }); ./Remove the phone key/value pair student.clear(); } List Mapping 5
  • 6. IV. Control Flow 🕹 const animal = 'Fox'; if (animal == 'Cat' .| animal .= 'Dog') { print('Animal is a house pet.'); } else { print('Animal is not a house pet.'); } If else statement const trafficLight = 'yellow'; var command = ''; if (trafficLight .= 'red') { command = 'Stop'; } else if (trafficLight .= 'yellow') { command = 'Slow down'; } else if (trafficLight .= 'green') { command = 'Go'; } else { command = 'INVALID COLOR!'; } print(command); If else-if statement 6
  • 7. IV. Control Flow 🕹 const number = 3; switch (number) { case 0: print('zero'); break; case 1: print('one'); break; case 2: print('two'); break; case 3: print('three'); break; case 4: print('four'); break; default: print('something else'); } switch statement Noted: switch statement is usually faster than a series of if-else statements when there are many cases to check. This is because a switch statement uses a table lookup to determine which case to execute, while a series of if-else statements requires a linear search through each condition until a match is found. 7
  • 8. IV. Control Flow 🕹 While Loop while (condition) { ./ loop code } Do-while Loop do { ./ loop code } while (condition) for(Initialization; condition; incrdecr) { ./ loop body } For Loop For-in Loop List<int> myList = [1,2 ,1, 1, 4]; for(var num in myList){ print("item: $num"); } List<int> myList = [3,3 ,3, 4]; myList.forEach((element) { print("item: $element"); }); ForEach Loop Noted: forEach is that it is often faster and more efficient than using a traditional for loop, especially for large collections. This is because forEach uses an internal iterator that is optimized for performance, while a traditional for loop with an index variable may be slower due to the overhead of incrementing and checking the index variable on each iteration. 8
  • 9. V. Function 󰥲 In programming, a function is a block of code that performs a specific task or set of tasks. Functions can be thought of as small, self-contained units of code that can be reused throughout a program. 9
  • 10. V. Function 󰥲 int sum(int a, int b) .> a + b; void main() { int result = sum(5, 7); } Take parameters, Return values void printMessage(String message) { print(message); } void main() { printMessage("Hello, world!"); } Take parameters, No return values No parameters, Return values import 'dart:math'; int getRandomNumber() { final random = Random(); return random.nextInt(10) + 1; } void main() { int randomNum = getRandomNumber(); } No parameters, No return values void printList(List<int> numbers) { for (final number in numbers) { print(number); } } void main() { final List<int> numbers = [1, 2, 3, 4, 5]; printList(numbers); } 10
  • 11. VI. Nullability - Null Safety 📭 Null Safety in simple words means a variable cannot contain a ‘null’ value unless you initialized with null to that variable. With null safety, all the runtime null-dereference errors will now be shown in compile time. final String msg1 = null; Error Null can’t be assigned to a variable final String? msg2 = null; No error 11
  • 12. VI. Nullability - Null Safety 📭 void crushMessage(String msg) { print("MESSAGE: $msg"); } void main() { final String? name = "Hey, I'm a string!"; crushMessage(name); Error Null can’t be assigned to a variable } void crushMessage(String msg) { print("MESSAGE: $msg"); } void main() { final String? name = "Hey, I'm a string!"; crushMessage(name!); } Bug Solution 12
  • 13. VI. Enumeration 🥇🥈🥉 In Dart, enum is a special data type that represents a group of related constants. An enum declaration consists of a list of named constant values, called enum members. Window MacOS Linux 13
  • 14. VI. Enumeration 🥇🥈🥉 enum CustomerType { regular, premium, vip } void main() { CustomerType customerType = CustomerType.premium; switch (customerType) { case CustomerType.regular: print('This is a regular customer.'); break; case CustomerType.premium: print('This is a premium customer.'); break; case CustomerType.vip: print('This is a VIP customer.'); break; } } 14
  • 15. V. CLASSES 󰥍 In Dart, a class is a blueprint for creating objects that have similar characteristics and behavior. It defines a set of attributes (also known as properties or instance variables) and methods that can be used to manipulate those attributes. 15
  • 16. IV. CLASSES 󰥍 enum Gender{Male, Female} class Person { final String name; final int age; final Gender gender; final String? occupation; ./ constructor Person({ required this.name, required this.age, required this.gender, this.occupation, }); ./Method or Behavior void walk(){} void speak(){} void eat(){} } void main() { Person phanith = Person(name: "Phanith", age: 20, gender: Gender.Male, occupation: "Student"); } Property Constructor Method 16
  • 17. VII. Object-Oriented Programming 🔥 Dart is an object-oriented programming language, and it supports all the concepts of object-oriented programming such as classes, object, inheritance, mixin, and abstract classes. As the name suggests, it focuses on the object and objects are the real-life entities. The Object-oriented programming approach is used to implement the concept like polymorphism, data-hiding, etc. The main goal of oops is to reduce programming complexity and do several tasks simultaneously 17
  • 18. Encapsulation Encapsulation is one of the important concepts of object-oriented programming. Before learning about dart encapsulation, you should have a basic understanding of the class and object in dart. Encapsulation means hiding data within a library, preventing it from outside factors. It helps you control your program and prevent it from becoming too complicated 18
  • 19. Encapsulation class Student { String _name; int _age; String _address; String _phone; Student(this._name, this._age, this._address, this._phone); ./ Getters String get name .> _name; int get age .> _age; String get address .> _address; String get phone .> _phone; ./ Setters set name(String name) .> this._name = name; set age(int age) .> _age = age; set address(String address) .> _address = address; set phone(String phone) .> _phone = phone; @override String toString() { return 'Student: $_name, $_age, $_address, $_phone'; } } void main() { Student student = Student('John', 20, '123 Main St', '555-555-5555'); print(student.toString()); } 19
  • 20. Inheritance Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a new class, called the subclass or derived class, to be based on an existing class, called the base class or superclass. The subclass inherits properties and methods from the base class, and can also add new properties and methods or modify the behavior of the inherited ones 20
  • 21. Inheritance class Animal { void eat() { print('The animal is eating'); } } class Dog extends Animal { void bark() { print('The dog is barking'); } } void main() { Dog myDog = Dog(); myDog.eat(); myDog.bark(); } 21
  • 22. Polymorphism Polymorphism is a concept in object-oriented programming that allows objects of different classes to be treated as if they were of the same type. In other words, it is the ability of an object to take on many forms. 22
  • 23. Polymorphism class Animal { void makeSound() { print('The animal makes a sound'); } } class Dog extends Animal { void makeSound() { print('The dog barks'); } } class Cat extends Animal { void makeSound() { print('The cat meows'); } } void main() { Animal animal = new Animal(); Animal dog = new Dog(); Animal cat = new Cat(); animal.makeSound(); dog.makeSound(); cat.makeSound(); } 23
  • 24. Abstract In programming, the term "abstract" refers to the concept of defining common interface or behavior without implementing it in detail. In object-oriented programming, an abstract class is a class that cannot be instantiated directly, but can be used as a base class for other classes. 24
  • 25. Abstract abstract class Shape { double area(); } class Circle extends Shape { double radius; Circle(this.radius); double area() { return 3.14 * radius * radius; } } class Rectangle extends Shape { double width, height; Rectangle(this.width, this.height); double area() { return width * height; } } void main() { Circle circle = Circle(5); Rectangle rectangle = Rectangle(5, 10); print(circle.area()); print(rectangle.area()); } 25
  • 26. Interface In programming, an interface is a specification of a set of methods and properties that a class must implement. An interface does not provide any implementation details, but rather defines a contract or agreement between different classes that share a common set of behaviors. 26
  • 27. Interface class CountryRule { void noGun() { print('No gun'); } } class SchoolRule { void noLongHair() { print('No long hair'); } } class Student implements CountryRule, SchoolRule { @override void noGun() { print('No gun'); } @override void noLongHair() { print('No long hair'); } } void main() { Student student = Student(); student.noGun(); student.noLongHair(); } 27
  • 28. I. Asynchronous Asynchronous programming is a programming paradigm that allows tasks to be executed concurrently and independently of each other, without having to wait for each task to complete before moving on to the next one. In other words, it enables a program to perform multiple operations at the same time, which can greatly improve its performance and responsiveness. 28
  • 29. VIII. Asynchronous Future<void> printNumbers() async { print('Starting to print numbers...'); ./ wait for 1 second before printing each number for (int i = 1; i .= 5; i.+) { await Future.delayed(Duration(seconds: 1)); print(i); } print('Finished printing numbers.'); } void main() { printNumbers(); print('Continuing to execute other tasks...'); } 29
  • 30. Practice Exercise 01: Write a program to sum the following series: Exercise 02: Accept 10 integers from the user to store them in an array, and display the average of the positive and negative numbers. Exercise 03: Write function convert decimal to binary. Exercise 04: (Simulation firing a gun) You progress to the third game of the Squid Game. For this game, six players will play together. Five bullets are put into a gun's round barrel which can hold up to six bullets. A staff from the game will start pointing the gun at the first player and firing the gun. If no bullet is fired, the player survives, otherwise, the player gets shot and die. The staff will do the same to all players one by one. Note that the staff will roll the barrel before each shooting. Which turn (1st to 6th) would you choose to increase your chance of survival? Write a program to simulate this gun shooting game one thousand rounds, and display the number of each player getting shot based on the turn they take to get shot. 30