SlideShare ist ein Scribd-Unternehmen logo
1 von 48
Downloaden Sie, um offline zu lesen
Kuala Lumpur
Wonyoung Choi
Lead Mobile Developer, OCBC Bank
Speaker Image
Placeholder
Glancing essential features
of Dart, before stepping
into Flutter
“Flutter is an open source framework by
Google for building beautiful, natively
compiled, multi-platform applications
from a single codebase.”
“But, This is not about Flutter.”
● Basic Syntax
● Object-Oriented Programming
● Functional Programming
● Asynchronous Programming
Basic Syntax
Variable / Constant
● int / double / String / bool
● Nullable / Non-nullable
● var - type inferring
dynamic - works like ‘Any’
● const - compile time
final - runtime
int attendees = 300;
double ticketPrice = 30.0;
String gdgChapter = "Kuala Lumpur”;
bool isHappy = true;
Variable / Constant
● int / double / String / bool
● Nullable / Non-nullable
● var - type inferring
dynamic - works like ‘Any’
● const - compile time
final - runtime
double? rotiTelur = null;
rotiTelur ??= 3.5;
Variable / Constant
● int / double / String / bool
● Nullable / Non-nullable
● var - type inferring
dynamic - works like ‘Any’
● const - compile time
final - runtime
var speakerName = "Toru";
speakerName = “Jecelyn";
dynamic month = "Dec";
month = 12;
Variable / Constant
● int / double / String / bool
● Nullable / Non-nullable
● var - type inferring
dynamic - works like ‘Any’
● const - compile time
final - runtime
final int year = 2022;
const String google = "Google";
final nextYear = 2023;
const myPhone = "Google Pixel 7 Pro";
Data Structures
● List: a basic collection like array
● Map: key-value pair
● Set: another basic collection, but not
allowing duplicated elements
List<String> btsMembers = [
"Jin",
"Suga",
"J-Hope",
"RM",
"Jimin",
"V",
"Jungkook"
];
btsMembers.add("Toru");
btsMembers.remove(“Toru");
Data Structures
Map<String, String> idols = {
"JYP": "TWICE",
“HYBE": "BTS",
"YG": "BLACKPINK"
};
idols["Starship"] = "IVE";
// What will happen?
print(idols["GDG"]);
● List: a basic collection like array
● Map: key-value pair
● Set: another basic collection, but not
allowing duplicated elements
Data Structures
final Set<String> blackPink = {
"Jisoo",
"Jennie",
"Rose",
"Lisa"
};
blackPink.add("Jisoo");
// What will happen?
print(blackPink);
● List: a basic collection like array
● Map: key-value pair
● Set: another basic collection, but not
allowing duplicated elements
Loop and condition
● if-else
● for loop
● while loop & do-while
● switch - with enum / given value
Method in Dart
● Return Type + Method name + Parameters
● named parameters with {}
● required keyword in parameters with {}
● optional parameters with []
Method in Dart
● Return Type + Method name + Parameters
● named parameters with {}
● required keyword in parameters with {}
● optional parameters with []
ReturnType methodName(ParameterType name) {
// Do whatever you want
}
Left Aligned Title
String namedParameter({
String first = "", String second = "", String third = ""
}) {
return "$first, $second, $third";
}
namedParameter(first: “Toru", second: “Android", third: "SG");
Left Aligned Title
String requiredParameter({
required String? first, required String? second
}) => "$first, $second";
To be nullable or with default value
String neitherRequiredAndNamed(
String first, String second
) => "$first, $second”;
neitherRequiredAndNamed("first", "second");
optionalParameter(String first, [String? second]) =>
"$first, $second”;
optionalParameter("first");
To be nullable or with default value
Object Oriented
Programming
Class
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
class Employee {
String employeeName;
String employeeAddr;
// default constructor
Employee(
this.employeeName,
this.employeeAddr
);
// named constructor
Employee.initialize({
String? name, String? addr
}): employeeName = name ?? "",
employeeAddr = addr ?? "" {
// Do something
}
}
Class
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
class ImmutableEmployee {
final String employeeName;
final String employeeAddr;
// constant constructor,
// it means an immutable object will be created
const ImmutableEmployee(
this.employeeName,
this.employeeAddr
);
}
ImmutableEmployee ie =
const ImmutableEmployee(
"Toru", “Kuala Lumpur”
);
Class
class _GDGChapter {
final String chapterName;
final List<String> chapterMembers;
String country;
_GDGChapter(
this.chapterName,
this.chapterMembers,
this.country
);
}
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
Class
// getter
String get firstMember {
return chapterMembers[0];
}
// setter
set countryName(String countryName) => {
country = countryName;
print(country);
}
var gdgkl = _GDGChapter(...);
gdgkl.firstMember;
gdgkl.countryName = "Malaysia";
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
Class
class Idol {
String name;
int count;
Idol({
required this.name,
required this.count
});
void sayName() {
print('We are $name.');
}
void sayMembersCount() {
print('$name has $count members!');
}
}
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
Class
class BoyGroup extends Idol {
BoyGroup(
String name,
int count,
): super(
name: name,
count: count
);
sayBoyGroup() {
print('We are a boygroup!');
}
}
class GirlGroup extends Idol {
GirlGroup(
String name,
int count,
) : super(
name: name,
count: count
);
sayGirlGroup() {
print('We are a girlgroup!');
}
}
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
Class
abstract class IdolInterface {
String name;
IdolInterface(this.name);
void sayName();
}
class BoyGroup implements IdolInterface {
@override String name;
BoyGroup(this.name);
@override void sayName() {
print('We are $name.');
}
}
● Constructor
● Private class
● Getter / Setter - additional properties
● Inheritance
● Abstract class / interface
Abstract class works as an interface
Functional
Programming
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
Passed as a parameter,
Returned from a function,
Assigned into a variable.
void main() {
var f = greeting;
f('Hello KL');
greeting2("KL peeps,", (str)=>{print("Selamat Pagi, $str")});
}
greeting(String text) {
print('$text, we are GDG');
}
greeting2(String text, Function callback) {
callback(text);
}
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
final List<String> btsMembers = [
"Jin",
"Suga",
"J-Hope",
"RM",
"Jimin",
"V",
"Jungkook"
];
var btsSet = btsMembers.toSet();
var btsMap = btsMembers.asMap();
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
var btsSet = btsMembers.toSet();
var btsSet2 = Set.from(btsMembers);
var btsMap = btsMembers.asMap();
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
final List<String> blackPink = [
"Jisoo",
"Jennie",
"Rose",
"Lisa"
];
final newBP = blackPink.map((x) {
return 'BlackPink, $x';
}); // returns Iterable
print(newBP);
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
final List<String> blackPink = [
"Jisoo",
"Jennie",
"Rose",
"Lisa"
];
final newBP = blackPink.map((x) =>
‘BlackPink, $x’); // arrow function
print(newBP);
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
Map<String, String> idols = {
"JYP": "TWICE",
"HYBE": "BTS",
"YG": "BLACKPINK",
"Starship": "IVE"
};
final result = idols.map((k, v) =>
MapEntry(
'Enter corp $k', 'Idol $v’
)
);
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
List<Map<String, String>> gdg = [
{
'name': 'Toru',
'domain': 'Android'
},
{
'name': 'Hassan',
'domain': 'Android',
},
{
'name': 'Jecelyn',
'domain': 'Web',
},
{
'name': 'Vin',
'domain': 'Web',
}
];
final web = gdg.where((x) => x['domain'] == 'Web');
print(web.toList());
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
List<int> numbers = [1, 3, 5, 7, 9];
final result = numbers.reduce((prev, next) =>
prev + next
);
print(result); // result is 25
Must return the same type with parameters
Functional Programming in Dart
● Function as the first-order object
● Transforming from collections and map
● map()
● where()
● reduce()
Methods for FP are cascadable!
final list = ['Nasi Lemak', 'Roti Canai', 'CKT'];
var result =
list.map({ ... }).take(2).toList();
Asynchronous
Programming
Asynchronous Programming
● Future - obtaining a value in the future.
● async, await - running code sequentially.
Future<String> futureStr = Future.value('GDG');
Future<int> futureInt = Future.value(100);
Asynchronous Programming
● Future - obtaining a value in the future.
● async, await - running code sequentially.
void main() {
print("Start");
Future.delayed(
Duration(seconds: 2), (){
print(["Toru", "Hassan", "Jecelyn"]);
});
print("End");
}
// Prints Start immediately
// Prints End immediately
// Prints the array 2 seconds later.
Asynchronous Programming
● Future - obtaining a value in the future.
● async, await - running code sequentially.
Future<List<String>> fetchSpeakers(String domain) async {
print("Start");
List<String> result = [];
await Future.delayed(
const Duration(seconds: 2), () {
print("Fetched");
if (domain == 'Android') {
result = ["Toru", "Hassan"];
} else {
result = ["Jecelyn", "Shang Yi"];
}
}
);
print("End");
return result;
}
void main() async {
final and = await fetchSpeakers('Android');
print("result: $and");
final other = await fetchSpeakers();
print("result: $other");
}
Use await, to call a method returning Future
Asynchronous!
Asynchronous Programming
● Future - obtaining a value in the future.
● async, await - running code sequentially.
Furthermore…
How could we use Dart in more Dart way?
Thank you!
@TORU_0239
TORU0239
Linkedin: toruchoi

Weitere ähnliche Inhalte

Ähnlich wie Glancing essential features of Dart, before stepping into Flutter

Types End-to-End @ samsara
Types End-to-End @ samsaraTypes End-to-End @ samsara
Types End-to-End @ samsaraStephen Wan
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDartLoc Nguyen
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Raffi Krikorian
 
#include iostream #include fstream #include string #incl.pdf
#include iostream #include fstream #include string #incl.pdf#include iostream #include fstream #include string #incl.pdf
#include iostream #include fstream #include string #incl.pdfaptexx
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into SwiftSarath C
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsAlfonso Peletier
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attributeRichard Martens
 
Structured web programming
Structured web programmingStructured web programming
Structured web programmingahfast
 

Ähnlich wie Glancing essential features of Dart, before stepping into Flutter (20)

Types End-to-End @ samsara
Types End-to-End @ samsaraTypes End-to-End @ samsara
Types End-to-End @ samsara
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Overloading
OverloadingOverloading
Overloading
 
#include iostream #include fstream #include string #incl.pdf
#include iostream #include fstream #include string #incl.pdf#include iostream #include fstream #include string #incl.pdf
#include iostream #include fstream #include string #incl.pdf
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attribute
 
All things that are not code
All things that are not codeAll things that are not code
All things that are not code
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Structured web programming
Structured web programmingStructured web programming
Structured web programming
 
Lecture5
Lecture5Lecture5
Lecture5
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 

Mehr von Toru Wonyoung Choi

The use case of a scalable architecture
The use case of a scalable architectureThe use case of a scalable architecture
The use case of a scalable architectureToru Wonyoung Choi
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedToru Wonyoung Choi
 
Building an app with Google's new suites
Building an app with Google's new suitesBuilding an app with Google's new suites
Building an app with Google's new suitesToru Wonyoung Choi
 
Slide_Concat_adapter_july_2020
Slide_Concat_adapter_july_2020Slide_Concat_adapter_july_2020
Slide_Concat_adapter_july_2020Toru Wonyoung Choi
 
activity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopiactivity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopiToru Wonyoung Choi
 
CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Songdo 2019CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Songdo 2019Toru Wonyoung Choi
 
CameraX, MLKit and AutoML at DevFest Cebu 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019CameraX, MLKit and AutoML at DevFest Cebu 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019Toru Wonyoung Choi
 

Mehr von Toru Wonyoung Choi (10)

The use case of a scalable architecture
The use case of a scalable architectureThe use case of a scalable architecture
The use case of a scalable architecture
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
Building an app with Google's new suites
Building an app with Google's new suitesBuilding an app with Google's new suites
Building an app with Google's new suites
 
datastore_devfest2020_incheon
datastore_devfest2020_incheondatastore_devfest2020_incheon
datastore_devfest2020_incheon
 
Slide_Concat_adapter_july_2020
Slide_Concat_adapter_july_2020Slide_Concat_adapter_july_2020
Slide_Concat_adapter_july_2020
 
activity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopiactivity_and_fragment_may_2020_lakopi
activity_and_fragment_may_2020_lakopi
 
camera_x_beyond_alpha
camera_x_beyond_alphacamera_x_beyond_alpha
camera_x_beyond_alpha
 
Slide_For_GDGKL_devfest_2019
Slide_For_GDGKL_devfest_2019Slide_For_GDGKL_devfest_2019
Slide_For_GDGKL_devfest_2019
 
CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Songdo 2019CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Songdo 2019
 
CameraX, MLKit and AutoML at DevFest Cebu 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019CameraX, MLKit and AutoML at DevFest Cebu 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Glancing essential features of Dart, before stepping into Flutter

  • 1. Kuala Lumpur Wonyoung Choi Lead Mobile Developer, OCBC Bank Speaker Image Placeholder Glancing essential features of Dart, before stepping into Flutter
  • 2. “Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.”
  • 3. “But, This is not about Flutter.”
  • 4. ● Basic Syntax ● Object-Oriented Programming ● Functional Programming ● Asynchronous Programming
  • 6. Variable / Constant ● int / double / String / bool ● Nullable / Non-nullable ● var - type inferring dynamic - works like ‘Any’ ● const - compile time final - runtime int attendees = 300; double ticketPrice = 30.0; String gdgChapter = "Kuala Lumpur”; bool isHappy = true;
  • 7. Variable / Constant ● int / double / String / bool ● Nullable / Non-nullable ● var - type inferring dynamic - works like ‘Any’ ● const - compile time final - runtime double? rotiTelur = null; rotiTelur ??= 3.5;
  • 8. Variable / Constant ● int / double / String / bool ● Nullable / Non-nullable ● var - type inferring dynamic - works like ‘Any’ ● const - compile time final - runtime var speakerName = "Toru"; speakerName = “Jecelyn"; dynamic month = "Dec"; month = 12;
  • 9. Variable / Constant ● int / double / String / bool ● Nullable / Non-nullable ● var - type inferring dynamic - works like ‘Any’ ● const - compile time final - runtime final int year = 2022; const String google = "Google"; final nextYear = 2023; const myPhone = "Google Pixel 7 Pro";
  • 10. Data Structures ● List: a basic collection like array ● Map: key-value pair ● Set: another basic collection, but not allowing duplicated elements List<String> btsMembers = [ "Jin", "Suga", "J-Hope", "RM", "Jimin", "V", "Jungkook" ]; btsMembers.add("Toru"); btsMembers.remove(“Toru");
  • 11. Data Structures Map<String, String> idols = { "JYP": "TWICE", “HYBE": "BTS", "YG": "BLACKPINK" }; idols["Starship"] = "IVE"; // What will happen? print(idols["GDG"]); ● List: a basic collection like array ● Map: key-value pair ● Set: another basic collection, but not allowing duplicated elements
  • 12. Data Structures final Set<String> blackPink = { "Jisoo", "Jennie", "Rose", "Lisa" }; blackPink.add("Jisoo"); // What will happen? print(blackPink); ● List: a basic collection like array ● Map: key-value pair ● Set: another basic collection, but not allowing duplicated elements
  • 13. Loop and condition ● if-else ● for loop ● while loop & do-while ● switch - with enum / given value
  • 14. Method in Dart ● Return Type + Method name + Parameters ● named parameters with {} ● required keyword in parameters with {} ● optional parameters with []
  • 15. Method in Dart ● Return Type + Method name + Parameters ● named parameters with {} ● required keyword in parameters with {} ● optional parameters with [] ReturnType methodName(ParameterType name) { // Do whatever you want }
  • 16. Left Aligned Title String namedParameter({ String first = "", String second = "", String third = "" }) { return "$first, $second, $third"; } namedParameter(first: “Toru", second: “Android", third: "SG");
  • 17. Left Aligned Title String requiredParameter({ required String? first, required String? second }) => "$first, $second"; To be nullable or with default value
  • 18. String neitherRequiredAndNamed( String first, String second ) => "$first, $second”; neitherRequiredAndNamed("first", "second");
  • 19. optionalParameter(String first, [String? second]) => "$first, $second”; optionalParameter("first"); To be nullable or with default value
  • 21. Class ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface class Employee { String employeeName; String employeeAddr; // default constructor Employee( this.employeeName, this.employeeAddr ); // named constructor Employee.initialize({ String? name, String? addr }): employeeName = name ?? "", employeeAddr = addr ?? "" { // Do something } }
  • 22. Class ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface class ImmutableEmployee { final String employeeName; final String employeeAddr; // constant constructor, // it means an immutable object will be created const ImmutableEmployee( this.employeeName, this.employeeAddr ); } ImmutableEmployee ie = const ImmutableEmployee( "Toru", “Kuala Lumpur” );
  • 23. Class class _GDGChapter { final String chapterName; final List<String> chapterMembers; String country; _GDGChapter( this.chapterName, this.chapterMembers, this.country ); } ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface
  • 24. Class // getter String get firstMember { return chapterMembers[0]; } // setter set countryName(String countryName) => { country = countryName; print(country); } var gdgkl = _GDGChapter(...); gdgkl.firstMember; gdgkl.countryName = "Malaysia"; ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface
  • 25. Class class Idol { String name; int count; Idol({ required this.name, required this.count }); void sayName() { print('We are $name.'); } void sayMembersCount() { print('$name has $count members!'); } } ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface
  • 26. Class class BoyGroup extends Idol { BoyGroup( String name, int count, ): super( name: name, count: count ); sayBoyGroup() { print('We are a boygroup!'); } } class GirlGroup extends Idol { GirlGroup( String name, int count, ) : super( name: name, count: count ); sayGirlGroup() { print('We are a girlgroup!'); } } ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface
  • 27. Class abstract class IdolInterface { String name; IdolInterface(this.name); void sayName(); } class BoyGroup implements IdolInterface { @override String name; BoyGroup(this.name); @override void sayName() { print('We are $name.'); } } ● Constructor ● Private class ● Getter / Setter - additional properties ● Inheritance ● Abstract class / interface Abstract class works as an interface
  • 29. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() Passed as a parameter, Returned from a function, Assigned into a variable.
  • 30. void main() { var f = greeting; f('Hello KL'); greeting2("KL peeps,", (str)=>{print("Selamat Pagi, $str")}); } greeting(String text) { print('$text, we are GDG'); } greeting2(String text, Function callback) { callback(text); }
  • 31. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() final List<String> btsMembers = [ "Jin", "Suga", "J-Hope", "RM", "Jimin", "V", "Jungkook" ]; var btsSet = btsMembers.toSet(); var btsMap = btsMembers.asMap();
  • 32. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() var btsSet = btsMembers.toSet(); var btsSet2 = Set.from(btsMembers); var btsMap = btsMembers.asMap();
  • 33. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() final List<String> blackPink = [ "Jisoo", "Jennie", "Rose", "Lisa" ]; final newBP = blackPink.map((x) { return 'BlackPink, $x'; }); // returns Iterable print(newBP);
  • 34. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() final List<String> blackPink = [ "Jisoo", "Jennie", "Rose", "Lisa" ]; final newBP = blackPink.map((x) => ‘BlackPink, $x’); // arrow function print(newBP);
  • 35. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() Map<String, String> idols = { "JYP": "TWICE", "HYBE": "BTS", "YG": "BLACKPINK", "Starship": "IVE" }; final result = idols.map((k, v) => MapEntry( 'Enter corp $k', 'Idol $v’ ) );
  • 36. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() List<Map<String, String>> gdg = [ { 'name': 'Toru', 'domain': 'Android' }, { 'name': 'Hassan', 'domain': 'Android', }, { 'name': 'Jecelyn', 'domain': 'Web', }, { 'name': 'Vin', 'domain': 'Web', } ]; final web = gdg.where((x) => x['domain'] == 'Web'); print(web.toList());
  • 37. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce() List<int> numbers = [1, 3, 5, 7, 9]; final result = numbers.reduce((prev, next) => prev + next ); print(result); // result is 25 Must return the same type with parameters
  • 38. Functional Programming in Dart ● Function as the first-order object ● Transforming from collections and map ● map() ● where() ● reduce()
  • 39. Methods for FP are cascadable!
  • 40. final list = ['Nasi Lemak', 'Roti Canai', 'CKT']; var result = list.map({ ... }).take(2).toList();
  • 42. Asynchronous Programming ● Future - obtaining a value in the future. ● async, await - running code sequentially. Future<String> futureStr = Future.value('GDG'); Future<int> futureInt = Future.value(100);
  • 43. Asynchronous Programming ● Future - obtaining a value in the future. ● async, await - running code sequentially. void main() { print("Start"); Future.delayed( Duration(seconds: 2), (){ print(["Toru", "Hassan", "Jecelyn"]); }); print("End"); } // Prints Start immediately // Prints End immediately // Prints the array 2 seconds later.
  • 44. Asynchronous Programming ● Future - obtaining a value in the future. ● async, await - running code sequentially. Future<List<String>> fetchSpeakers(String domain) async { print("Start"); List<String> result = []; await Future.delayed( const Duration(seconds: 2), () { print("Fetched"); if (domain == 'Android') { result = ["Toru", "Hassan"]; } else { result = ["Jecelyn", "Shang Yi"]; } } ); print("End"); return result; } void main() async { final and = await fetchSpeakers('Android'); print("result: $and"); final other = await fetchSpeakers(); print("result: $other"); } Use await, to call a method returning Future Asynchronous!
  • 45. Asynchronous Programming ● Future - obtaining a value in the future. ● async, await - running code sequentially.
  • 47. How could we use Dart in more Dart way?