스터디/Dart13 [Dart] #3.5 Typedef Typedef 간단한 데이터의 alias(별칭)를 만들 때 사용함. 예제) 형식 Map의 alias를 UserInfo로 두기. typedef UserInfo = Map; String sayHi(UserInfo userInfo) { return "Hi ${userInfo['name']}"; //Map userinfo 요소 중, key가 name인 것의 value를 가져옴 } void main() { sayHi({'name' : 'nico'}); } structured data에 대한 alias는 class 사용 --> 출처: https://nomadcoders.co/dart-for-beginners/lectures/4113 2024. 1. 10. [Dart] #3.4 QQ Operator ?? and ??= ?? ??= 이름을 대문자로 return하는 함수 String capitalizeName(String name) => name.toUpperCase(); String capitalizeName(String? name) => name.toUpperCase(); --> 오류 b/c if name is null, can't use toUpperCase 해결 방법 1. if문 String capitalizeName(String? name) { if (name != null) { return name.toUpperCase(); } return 'ANON'; //if name is NULL } 해결 방법 2. ? : and fat arrow String capitalizeName(String? name) => na.. 2024. 1. 10. [Dart] #3.3 Optional Positional Parameters String sayHello(String name, int age, [String? country = 'cuba']) => 'Hello $name, you are $age years old from $country'; void main(){ sayHello('nico',12); } country is not required, and default value is set. Nico doesn't use this a lot! like less than ten times. Nico uses 'named' parameters a lot !! 출처: https://nomadcoders.co/dart-for-beginners/lectures/4111 All Courses – 노마드 코더 Nomad Coders 초급.. 2024. 1. 10. [Dart] #3.2 Recap ^_^ (positional,named,required,default) //positional parameter cf.positional은 required가 default이다. String P_sayHello(String name, int age, String country) { return "Hello $name, you are $age, and you come from $country"; } //named parametre String N_sayHello({String name, int age, String country}) { return "Hello $name, you are $age, and you come from $country"; } //required String R_sayHello({ required String name, required int age, .. 2024. 1. 10. [Dart] #3.1 Named Parameters ({ }) String sayHello4({String name, int age, String country}){ return "Hello $name, you are $age, and you come from $country"; } String sayHello2({ String name = 'anon', int age = 99, String country = 'wakanda', }){ return "Hello $name, you are $age, and you come from $country"; } String sayHello3({ required String name, required int age, required String country, }){ return "Hello $name, you are $age.. 2024. 1. 10. [Dart] #3.0 Functions void V_sayHello(String name){ //void means this funtion doesn't return anything print("hello $name nice to meet you"); } String S_sayHello(String name){ return "hello $name nice to meet you"; } String S2_sayHello(String name) => "hello $name nice to meet you" //fat arrow syntax. immediate return. use when your function only has one line code. //don't have to use Curly Brakets void main() { print.. 2024. 1. 10. 이전 1 2 3 다음