File tree Expand file tree Collapse file tree
flutter_course/dart_functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ main () {
2+ // Functions
3+ // https://dart.dev/language/functions
4+
5+ // using the dynamic as parameters :eyes:
6+ union (a, b) {
7+ print (a + b);
8+ }
9+
10+ union (2.8 , 47 );
11+
12+ // Named parameters
13+ // https://dart.dev/language/functions#named-parameters
14+ String named ({String name = 'Robson' , int age = 47 }) {
15+ return '$name has age' ;
16+ }
17+
18+ print (named ()); // using default parameters
19+ print (named (age: 48 , name: 'Ana Mara' )); // using named parameters
20+
21+ // Optional positional parameters
22+ // https://dart.dev/language/functions#optional-positional-parameters
23+ String say (String from, String msg, [String ? device]) {
24+ var result = '$from says $msg ' ;
25+ if (device != null ) {
26+ result = '$result with a $device ' ;
27+ }
28+ return result;
29+ }
30+
31+ print (say ("Robson" , "Hello Dart and Flutter" ));
32+ print (say ("Robson" , "Hello Dart and Flutter" , 'Android' ));
33+
34+ // Functions as first-class objects
35+ // https://dart.dev/language/functions#functions-as-first-class-objects
36+
37+ // function as var
38+ final sum = (int a, int b) => a + b;
39+ print (sum);
40+ print (sum (10 , 30 ));
41+
42+ // function as param
43+ var result = [1 , 2 , 3 ].fold (1 , sum);
44+ print (result);
45+ }
Original file line number Diff line number Diff line change 1+ # Generated by pub
2+ # See https://dart.dev/tools/pub/glossary#lockfile
3+ packages: {}
4+ sdks:
5+ dart: ">=3.1.3 <4.0.0"
You can’t perform that action at this time.
0 commit comments