본문 바로가기

반응형

Flutter/Dart

(10)
Dart 비동기 프로그래밍 Asynchronous Programming 출처 : 유튜브 코드팩토리 비동기 프로그래밍 Future, Await, Returning Future, Stream, Stream 기본기, Broadcast Stream, Stream값 변경하기, Stream 함수, Stream에서의 async 프로그래밍, Yield 동기는 하나의 스레드에서 하나의 로직을 실행하는동안 cpu 사용 불가 서버 요청을했을 때 cpu 사용불가 - cpu 낭비 비효율 비동기 => 서버요청을 했을 때 cpu 사용 가능하도록 ## Future - 미래에 받아올 값 Future name = Future.value('가나다'); // 미래에 받아올 스트링 값 Future number = Future.value(1); @ delayed는 두개의 파라미터 (지연할 기간 Duration, ..
Dart 함수형 프로그래밍 Functional Programming 출처 : 유튜브 코드팩토리 함수형 프로그래밍 형변환, 리스트, Map, Set,Where,Reduce,Fold,Cascading Operator, ## 형변환 - 함수형 프로그래밍의 기본 void main(){ List blackPink = ['로제','지수','리사','제니']; print(blackPink); print(blackPink.asMap()); // 리스트를 맵으로 변환 print(blackPInk.toSet()); // 리스트를 set으로 변환 @ Map 생성 Map blackPinkMap = blackPink.asMap(); @ Iterable- () 괄호 형태, 일종의 리스트, 키와 value는 Iterable 형태 print(blackPinkMap.keys) // Iterable 형..
Dart 객체 지향 프로그래밍 OOP 출처 : 코드팩토리 객체지향 프로그래밍 생성자, Getter and Setter, Private 속성, 상속 Inheritance, Override, static, Interface, Generic 클래스 - 기능을 모아둔 것 인스턴스 - 클래스로 만든 것, 무한히 생성 가능 ## 생성자 constructor @ 클래스 생성 void main(){ Idol blackPink = const Idol( '블랙핑크',['제니','지수','리사','로제']); // 클래스로 인스턴스 생성 , const로 선언할 수 있는 파라미터만 있는 경우에는 const 인스턴스 생성 가능 print(blackPink.name); blackPink.sayHello(); Idol bts = Idol('BTS',['진','정국']..
Dart 언어 기본기 출처 : 유튜브 코드팩토리, 1시간만에 끝내는 Dart 언어 기본기 Hello World, 변수 선언하기, 변수 타입, Nullable, Final vs Const, Operators, List, Map, Set, If문, Loops, Enum, 함수, Typedef ## hello print void main(){ print('Hello Code Factory'); } ## 변수 선언 - variable void main(){ var name(변수명) = 'studying';(변수값) print(name) @ 변수값 변경 name = '플러터 프로그래밍'; print(name) @ 코드는 순서대로 실행된다. var name = 'studying22'; @ 이미 있는 이름의 변수를 선언하는 것은 불가능하..
Dart Map - entries, asMap void main(){ Map map = { 'Apple' : '사과', 'Banana' : '바나나', 'Kiwi': '키위', }; # Mapping - map => (entry) final newMap = map. entries.map((entry){ // entry 안에 'Apple':'사과' 이렇게 들어간다. final key = entry. key; final value = entry. value; return '$key 는 한글로 $value 입니다.'; }); print(newMap); // 결과 : (Apple는 한글로 사과 입니다., Banana는 한글로 바나나 입니다., Kiwi는 한글로 키위입니다.) } * map.entries.forEach, map.entries.reduce, m..
Dart List - forEach, map, reduce, fold List도 클래스 # forEach 함수 - Looping - for 함수쓰는 것과 같음 List student = [ '가방', '노트북', '충전기', ] student.forEach((value){ // 함수를 인자로 받는다. parameter안에 이름은 아무거나 가능 print(value); }); 결과: 가방 노트북 충전기 # map - Mapping final newList = student.map((value){ // Map은 return 값을 받을 수 있다. return '학생이 챙겨야할 물건은 $value입니다.'; }); print(newList); 결과: (학생이 챙겨야할 물건은 가방입니다.,학생이 챙겨야할 물건은 노트북입니다.,학생이 챙겨야할 물건은 충전기입니다.) // 새로운 It..
Dart Class 클래스 # Class 클래스 생성 class Player { String name = '공부중'; // 타입을 꼭 명시해 주어야함 int xp = 1500; // 타입을 꼭 명시해 주어야함 void sayHello(){ var name = '121'; print("Hi my name is ${this.name}"); // 변수와 class 내 property의 이름이 겹칠 때만 this 사용 그 외에는 $name 사용 } } void main() { var player = Player(); // 클래스로 객체 생성 print(player.name); player.name = 'asdkfj'; // 바꾸고 싶지 않다면 class 내에서 final로 선언 print(player.name); player.sayHel..
Dart Functions 함수 # Defining a Function 리턴할데이터타입 함수이름(인자데이터타입 인자이름){} void sayHello(String name) { // void 함수 아무것도 return 하지 않는다. print ("Hello $name nice to meet you"); } String sayHello(String name) { // String을 return 하는 함수 return "Hello $name nice to meet you"; } String sayHello(String name) =>"Hello $name nice to meet you"; // 코드가 한 줄짜리 일 때 fat arrow syntax를 이용 // fat arrow syntax => 는 곧바로 return 한다라는 의미 # N..

반응형