본문 바로가기

Dart

(14)
[Dart] Map 고급 - entries, asMap map.entries 를 이용하여 iterable 객체로 변환하여 List 객체의 내장함수를 사용하여 전처리 함. void main() { Map map = {'Apple':'사과','Banana':'바나나','Kiwi':'키위',}; print(map.keys); # Iterable 객체임 print(map.values); # Iterable 객체임 print(map.keys.toList()); # List 객체임 print(map.values.toList()); # List 객체임 print('---------- 01 ----------'); print('map.keys is Iterable'); print(map.keys is Iterable); # true print("map.keys.toList..
[Dart] List 고급 - forEach, map, fold, reduce void main() { //looping //Mapping //Reduce/Fold List students = ['김군','이군','박군','홍군','정군',]; students.forEach((value){ print(value); }); print('---------- && ----------'); for(String value in students){ print(value); } print('---------- && ----------'); final newList = students.map((value){ return 'My name is $value.'; }); print(newList); print(students); print(newList is Iterable); print(studen..
[Dart] Class - Cascade void main() { Student kim = new Student('kim', 15); kim.sayName(); kim.sayAge(); new Student('lee', 20) ..sayName() ..sayAge(); } // 학생 class Student { String name; int age; Student(this.name, this.age); void sayName() { print('my name is ${this.name}'); } void sayAge() { print('my age is ${this.age}'); } } --------------------------------------------[result] my name is kim my age is 15 my name ..
[Dart] Class - interface void main() { GradeA kim = new GradeA('kim'); kim.sayName(); GradeB lee = new GradeB('lee'); lee.sayName(); } // 학생, 학생이름 class Student { String? name; void sayName() {} } class GradeA implements Student { String? name; GradeA(this.name); void sayName() { print('My name is ${this.name}'); } } class GradeB implements Student { String? name; GradeB(this.name); void sayName() { print('My name is ${..
[Dart] Class - super, this 자신의 클래스에 없으면 부모의 클래스를 찾아서 name, grade 를 출력한다. 자신의 클래스에 name, grade 변수가 있다면 super/this 키워드를 주의해서 사용할 것 void main() { Student kim = new Student(1, 'kim'); kim.who(); GradeOne lee = new GradeOne(['국어','수학','영어'], 2, 'lee'); lee.who(); print(lee.subject); lee.sayInfo(); } // 학생, 학년, 학생이름 class Student { int grade; String name; Student(this.grade, this.name); void who() { print('I am $name, grade is ..
[Dart] Class - Static void main() { // Method overriding Student.schoolName = 'Korea'; Student kim = new Student(1, 'kim'); kim.who(); } // 학생, 학교이름, 학년, 학생이름 class Student { static String? schoolName; int grade; String name; Student(this.grade, this.name); void who() { print('I am $name, grade is $grade, school name is $schoolName'); } } --------------------------------------------[result] I am kim, grade is 1, scho..
[Dart] Class - Method override Method override & super kewword void main() { // Method overriding Parent parent = new Parent(3); Child child = new Child(3); print('parent.cal():' + parent.cal().toString()); print('child.cal():' + child.cal().toString()); } class Parent { final int _number; Parent(this._number); int cal() { return this._number * this._number; } } class Child extends Parent { Child(int number) : super(number); ..
[Dart] Class - 상속/Inheritance void main() { House house1 = new House(4, 2); house1.aboutFloors(); house1.aboutRooms(); print('------------- APT -------------'); Apt apt1 = new Apt(5, 3, 'Rome'); apt1.aboutFloors(); apt1.aboutRooms(); apt1.aboutName(); print('------------- Villa -------------'); Villa villa1 = new Villa(1, 2, 'Milano'); villa1.aboutFloors(); villa1.aboutRooms(); villa1.aboutName(); } class House { // private ..