함수 정의 및 실행
String sayHello(String name){
return 'Hello $name nice to meet you!';
}
void main() {
print(sayHello("steven"));
}
fat arrow syntax ({}
나 return
이 필요 없게 된다.)
String sayHello(String name) => 'Hello $name nice to meet you!'; // fat arrow syntax => 바로 return하는 거랑 같은 의미
void main() {
print(sayHello("steven"));
}
String sayHello(String name ,int age, String country) {
return 'Hello $name nice to meet you! you are $age and you come from $country';
}
void main() {
print(sayHello("steven",25,'England'));
}
not best practice (순서가 헷갈리거나 까먹을 수 있음)
String sayHello({required String name = 'anonymous' ,required int age = 99, required String country ='wakanda'}) {
return 'Hello $name nice to meet you! you are $age and you come from $country';
}
void main() {
print(sayHello(
name : "steven",
age : 25,
country : "England"
)); // Hello steven nice to meet you! you are 25 and you come from England
print(sayHello()); // Hello anonymous nice to meet you! you are 99 and you come from wakanda
}
String sayHello(String name, int age, [String? country = 'Wales']) =>
'Hello $name nice to meet you! you are $age and you come from $country';
void main() {
var result = sayHello(
'Steven',
25,
);
print(result);
// Hello Steven nice to meet you! you are 25 and you come from Wales
}