-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunny_func.dart
38 lines (32 loc) · 944 Bytes
/
funny_func.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* A function IS an object !
* We can assign a function to a variable
*/
void main() {
// positional parameters
avgThem(int n1, int n2) {
return 'Averaged value is ${(n1 + n2) / 2}';
}
print(avgThem(3, 7)); // this is a func call
// args passed by position
// Arrow function, same as above
avgThem2(int n1, int n2) => 'Averaged value is ${(n1 + n2) / 2}';
// named parameters
// fix fname to be required
namePlease({required String fname, String lname = ''}) {
return fname.toUpperCase() + ' ' + lname.toUpperCase();
}
namePlease(fname: 'Jedt');
namePlease(lname: 'Sitth', fname: 'jedt');
// Callback functions
// APIs in Dart use callback functions to handle events in Flutter
// First-class functions
whichBtn(Function callBackFn) {
var result = callBackFn();
return 'Result: $result';
}
print(whichBtn(getMouseBtn));
}
getMouseBtn() {
return 'I click Left Mouse Button';
}