학습/Dart

· 학습/Dart
Cascade Notation(Cascade Operator)기존에 클래스를 생성하고 해당 객체의 값을 변경하려면 다음과 같이 작성해야했다. Dart에서는 이렇게 taek.~~~ 이 중복을 줄일 수 있도록 할 수 있다고 한다.변경된 소스코드는 다음과 같다.class Player { String name; int xp; String team; Player({ required this.name, required this.xp, required this.team, }); void sayHello() { print("Hi, my name is $name"); }}void main() { var taek = Player(name: 'taek', xp: 1200, team: 'r..
· 학습/Dart
Named Constructor Parameters이전 포스팅을 보면 function처럼 argument를 받아서 클래스를 생성한다. 그러나 이건 class가 커질수록 argument가 많아져서 관리하기가 힘들다. function처럼 named parameters를 적용하기만 하면 된다. class Player { final String name; int xp; String team; int age; Player({ required this.name, required this.xp, required this.team, required this.age, }); void sayHello() { print("Hi my name is $name"); }}void main..
· 학습/Dart
1. Class가장 중요한 class에 대해서 알아보자. 다른 언어와의 차이점에 대해서도 잘 알아보아야 한다. 예로 Player라는 클래스를 작성해본다.class Player { String name = 'taek'; int xp = 1500; void sayHello() { print("Hi my name is $name"); }}void main() { // var player = new Player(); // new를 써도 되고 안써도된다. var player = Player(); print(player.name); player.name = 'lalala'; print(player.name);} class에서 property를 선언할때는 타입을 사용해서 정의한다. 이전 포..
· 학습/Dart
1. Optional Positional ParametersString sayHello( String name, int age, [String? country = 'korea']) => 'Hello $name, you are $age years old from $country';void main() { var result = sayHello('taek', 20); print(result);}일부 parameter에 null을 받으면 default value를 설정할 수 있게 한다.형식은 메서드의 매개변수에 대괄호[]를 하고 타입 뒤에 ?를 붙여서 null이 가능하게 만든 다음, 뒤에 default value를 설정해주는 것이다.   2. QQ Operator(Question Question..
· 학습/Dart
1. Defining a FunctionString sayHello(String name) { return 'Hello ${name} nice to meet you!';}void main() { print(sayHello('taek'));}기본적인 함수 정의는 자바와 비슷하다. 한줄짜리 함수는 fat arrow syntax를 적용시킬 수 있다.fat arrow syntax는 곧바로 return 하는 거랑 같은 의미이다.String sayHello(String name) =>'Hello ${name} nice to meet you!';// 더하기 함수num plus(num a, num b) => a + b;void main() { print(sayHello('taek'));}  2. Named Par..
· 학습/Dart
1. basic Data Typesvoid main() { String name = 'taek' or "taek"; // String (' 와 " 둘다 가능) boole alive = true; // boolean int age = 12; // integer double money = 12.99; // double num x = 12; // int와 double의 부모클래스 num num = 1.12;}Dart는 object와 class로 이루어져 있다는 것을 꼭 기억하자. 완전한 객체지향언어이다.  2. Listsvoid main() { var numbers = [1, 2, 3, 4]; // List numbers = [1, 2, 3, 4]; // 타입으로 선..
태기
'학습/Dart' 카테고리의 글 목록