-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from rosera/tastethedream-patch-12
Update ex4-3.md
- Loading branch information
Showing
1 changed file
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,35 @@ | ||
# 4.3 Returning values from Functions | ||
# 4.3 Using Optional Parameters | ||
|
||
# Example | ||
## Example 1 | ||
|
||
```dart | ||
void main() { | ||
DateTime timeLondon = getCurrentDateTime(0); | ||
DateTime timeNewYork = getCurrentDateTime(-7); | ||
print('London: $timeLondon'); | ||
print('New York: $timeNewYork'); | ||
printGreetingNamed(); | ||
printGreetingNamed(personName: "Rich"); | ||
printGreetingNamed(personName: "Mary", clientId: 001); | ||
} | ||
void printGreetingNamed({String personName = 'Stranger', | ||
int clientId = 999}){ | ||
if (personName.contains('Stranger')) { | ||
print('Employee: $clientId Stranger danger '); | ||
} else { | ||
print('Employee: $clientId $personName '); | ||
} | ||
} | ||
``` | ||
|
||
DateTime getCurrentDateTime(int hourDifference) { | ||
DateTime timeNow = DateTime.now(); | ||
DateTime timeDifference = timeNow.add(Duration(hours: hourDifference)); | ||
## Example 2 | ||
|
||
return timeDifference; | ||
``` | ||
void main() { | ||
printGreetingPositional("Rich"); | ||
printGreetingPositional("Rich", "Rose"); | ||
} | ||
void printGreetingPositional(String personName, [String? personSurname]){ | ||
print(personName); | ||
if (personSurname != null){ | ||
print(personSurname); | ||
} | ||
} | ||
``` | ||
|