SlideShare a Scribd company logo
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

More Related Content

PPTX
App_development55555555555555555555.pptx
PDF
Basic Dart Programming Language 2023.pdf
PPTX
GDSC Flutter Forward Workshop.pptx
PPTX
Chapter 2 Flutter Basics Lecture 1.pptx
PDF
Dart workshop
PDF
Functional Programming - Flutter Stuttgart 2022.pdf
PDF
Introduction to Dart
PDF
basics dart.pdf
App_development55555555555555555555.pptx
Basic Dart Programming Language 2023.pdf
GDSC Flutter Forward Workshop.pptx
Chapter 2 Flutter Basics Lecture 1.pptx
Dart workshop
Functional Programming - Flutter Stuttgart 2022.pdf
Introduction to Dart
basics dart.pdf

Similar to Glancing essential features of Dart, before stepping into Flutter (20)

PPTX
Dart programming language
PDF
Dart - en ny platform til webudvikling af Rico Wind, Google
PPTX
Dartprogramming
PPTX
Dart, unicorns and rainbows
PPTX
Dart London hackathon
PPTX
1-introduction-to-dart-programming.pptx
PPTX
Mobile Applications Development class 02 ntroduction to Drat
PDF
Dart
PPTX
Dart structured web apps
PPTX
introduction to dart --- Section two - 2.pptx
PPTX
pembelajaran tentang dart dalam bahasa inggris
PPTX
Dart PPT.pptx
PDF
Flutter tutorial for Beginner Step by Step
PDF
GDSC-FlutterBasics.pdf
PPT
No JS and DartCon
PPTX
advance-dart.pptx
PPTX
Dart 1 In Dart, a programming language developed by Google, data types are us...
PPTX
Dart Programming.pptx
PDF
Bronx study jam 1
PDF
Discover Dart - Meetup 15/02/2017
Dart programming language
Dart - en ny platform til webudvikling af Rico Wind, Google
Dartprogramming
Dart, unicorns and rainbows
Dart London hackathon
1-introduction-to-dart-programming.pptx
Mobile Applications Development class 02 ntroduction to Drat
Dart
Dart structured web apps
introduction to dart --- Section two - 2.pptx
pembelajaran tentang dart dalam bahasa inggris
Dart PPT.pptx
Flutter tutorial for Beginner Step by Step
GDSC-FlutterBasics.pdf
No JS and DartCon
advance-dart.pptx
Dart 1 In Dart, a programming language developed by Google, data types are us...
Dart Programming.pptx
Bronx study jam 1
Discover Dart - Meetup 15/02/2017
Ad

More from Toru Wonyoung Choi (11)

PDF
What's new in android: jetpack compose 2024
PDF
The use case of a scalable architecture
PDF
Jetpack, with new features in 2021 GDG Georgetown IO Extended
PDF
Building an app with Google's new suites
PDF
datastore_devfest2020_incheon
PDF
Slide_Concat_adapter_july_2020
PDF
activity_and_fragment_may_2020_lakopi
PDF
camera_x_beyond_alpha
PDF
Slide_For_GDGKL_devfest_2019
PDF
CameraX, MLKit and AutoML at DevFest Songdo 2019
PDF
CameraX, MLKit and AutoML at DevFest Cebu 2019
What's new in android: jetpack compose 2024
The use case of a scalable architecture
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Building an app with Google's new suites
datastore_devfest2020_incheon
Slide_Concat_adapter_july_2020
activity_and_fragment_may_2020_lakopi
camera_x_beyond_alpha
Slide_For_GDGKL_devfest_2019
CameraX, MLKit and AutoML at DevFest Songdo 2019
CameraX, MLKit and AutoML at DevFest Cebu 2019
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25-Week II
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Electronic commerce courselecture one. Pdf
Assigned Numbers - 2025 - Bluetooth® Document
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

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?