SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Último (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

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?