일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- GIT
- 의존성주입
- viewpager
- RecyclerView
- MVVM
- 스튜디오
- 안스
- WebView
- studio
- 안드로이드
- 깃헙
- 안드로이드 스튜디오
- ADB
- Android
- Github
- 코루틴
- build
- Gradle
- 유튜브
- Kotlin
- 코틀린
- coroutine
- image
- 레트로핏
- dart
- Retrofit
- 웹뷰
- 에러
- 안드로이드스튜디오
- error
- Today
- Total
목록Dart (4)
코딩하는 일용직 노동자

클래스 객체를 만들때 new 키워드를 생략이 가능하다. class Person { String name; int age; } var person = Person(); // new를 붙여도 되고 생략해도 된다. 생성자도 Java와 비슷하다. class Person { String name; int age; /* * String name, int age 로 하면 값을 받아서 다시 셋팅해주는 * 처리가 필요하지만 이렇게 하면 코드수를 줄일 수 있다. */ Person(this.name, this.age); } 코틀린의 .apply처럼 클래스의 값을 연속으로 셋팅해줄 수 있다. class Car { String _model; int _makeYear; void setModel(String model) { thi..

일반적인 메소드는 Java의 그것과 똑같다. void printMsg(String msg) { print(msg); } printMsg('Hello World'); 메소드에 파라메터명을 반드시 적도록 하는 옵션을 줄 수 있다. void printMsg({String msg}) { print(msg); } 이렇게 정의된 메소드를 파라메터명을 함께 표기해야 한다. printMsg(msg: '헬로 월드'); 단, 옵션의 경우 값을 넘겨도 되고, 안넘겨도 되는 nullable의 개념으로 생각해야 한다. 때문에 필수로 값을 넘겨야 하는 경우에는 옵션으로 지정하면 안된다. void userInfo(String name, {int age}) { print('$name $age'); } name은 필수, age는 옵션..

컬렉션 타입은 아래처럼 만든다. List 타입 List items = ['a', 'B', 'c']; var items = ['a', 'B', 'c']; 만들어진 List의 값을 꺼내오는 것은 java의 배열처럼 하면 된다. Dart에는 배열은 없고 List타입만 있다. print(items[0]); List타입은 java처럼 add, isEmpty 함수등을 이용할 수 있다. 두개의 List를 하나로 합치는 방법 var items1 = ['a', 'B', 'c']; var items2 = [...items1, 'd', 'e']; // 첫번째 값에 ...items1으로 넣었다. print(items2); Set 타입 Set itemSet = {'a', 'B', 'c'}; var itemSet = {'a', ..

아래 주소에서 쉽게 Dart문법을 이용해서 실행시켜볼 수 있다. https://dartpad.dartlang.org/ DartPad dartpad.dartlang.org 1.자료형 타입추론 방식을 사용한다. var a = 10; 이렇게 써도 되고 int a = 10; 이렇게 써도 된다. dynamic b = 10; 이런 문법도 있다. myFunc(dynamic param) { print('$param') } 이렇게 파라메터를 dynamic 타입으로 받게 된다면 myFunc(10); myFunc('Hello'); 를 넣어도 다 된다. 마치 자바의 제너릭과 비슷하다. num c = 10.1; 또한 숫자형을 모두 포함하는 num 이라는 자료형도 존재한다. 이것은 int 형이든 double 형이든 숫자형을 모두..