초기 환경설정
- flutter doctor
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.2.1 22D68 darwin-arm64, locale ko-KR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.80.0)
[✓] Connected device (2 available)
[✓] Network resources
Dart
void main() {
print('Hello, World!');
}
var name = 'Voyager I';
var year = 1977;
var antennaDiameter = 3.7;
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = {
'tags': ['saturn'],
'url': '//path/to/saturn.jpg'
};
if (year >= 2001) {
print('21st century');
} else if (year >= 1901) {
print('20th century');
}
for (final object in flybyObjects) {
print(object);
}
for (int month = 1; month <= 12; month++) {
print(month);
}
while (year < 2016) {
year += 1;
}
int fibonacci(int n) {
if (n == 0 || n == 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
var result = fibonacci(20);
flybyObjects.where((name) => name.contains('turn')).forEach(print);
- Imports : 다른 라이브러리들의 APIs를 가져다가 씀
- class : 설계도라고 생각, 재활용해서 사용
- enum : 여러 개의 타입 설정, 열거형, 확장할수 있음
enum PlanetType { terrestrial, gas, ice }
class Orbiter extends Spacecraft {
double altitude;
Orbiter(super.name, DateTime super.launchDate, this.altitude);
}
- mixin : 다중 class 상속, with 사용
mixin Piloted {
int astronauts = 1;
void describeCrew() {
print('Number of astronauts: $astronauts');
}
}
class PilotedCraft extends Spacecraft with Piloted {
}
- Interfaces
- abstract
- Async : callback hell를 피함, 비동기, async와 await사용
- future : 비동기 작업의 결과를 나타내며 미완료(value를 생성하기 전)또는 완료(value 생성)의 두 가지 상태를 가질 수 있다.
- Exceptions : 예외상황을 정의
if (astronauts == 0) {
throw StateError('No astronauts.');
}
try {
for (final object in flybyObjects) {
var description = await File('$object.txt').readAsString();
print(description);
}
} on IOException catch (e) {
print('Could not describe object: $e');
} finally
{
flybyObjects.clear();
}
}
변수
int lineCount;
if (weLikeToCount) {
lineCount = countLines();
} else {
lineCount = 0;
}
print(lineCount);
- late
late String name;
- Final and const : 상수값, 바꿀수 없다. 컴파일러가 메모리상에 최적화하고, 프로그램 성능에 도움이 될수 있다.
- List
const Object i = 3;
const list = [i as int];
const map = {if (i is int) i: 'int'};
const set = {if (list is List<int>) ...list};
Operators(연산)
- https://dart.dev/language/operators
~/ : 결과를 나눠서 정수로 나타내주세요, 즉 double타입은 안받음
- shift :
<< >> >>> , 속도가 빠름, 잘 사용은 안한다.
- XOR :
^
- OR :
|
- AND :
&
- as is is!
==,!=
&& : a조건과 b조건이 같다 다르다
- if null:
?? , 값이 null이라면 이값을 넣어줘