# Dart
# Important Concepts
- Every variable is an object, and every object is an instance of a class.
- numbers, functions, and null are objects.
- all objects inherit from the
Objectclass except for null.
- Dart is strongly typed by optional.
- Dart is null safe.
- If you want nullable add
?at the end.int?might be integer or null. Object?allows all objects- Uninitialized variables have value of null.
dynamiccan be used to disable static checking. Not recommended.
Objectallows all objects exceptnull.
- If you want nullable add
- Dart allows generic types.
- List
: list of ints - List
- List
main()is top level function.- Dart also supports top-level variables.
- Identifier can start with
__or letter - Dart doesn't have
public',protectedandprivate. If identifier started with__, it's private to its library. - Dart has both expression and statement
- Expressions have runtime value :
expression condition ? expr1 : expr2which has either expr1 or expr2 as runtime value - Statement has no value
if else statement. - Statement often contains one or more expressions, but an expression can't directly contain a statement.
- Expressions have runtime value :
- Dart has warnings and errors.
- Warnings tell you it might not work but executable
- Errors can be either compile time or run time. compile time error prevents executing, run time error raises exception
- Top-level and class variables are lazily initialized; the initialization code runs the first time the variable is used.
- if error you can use
lateto tell dart to run initializer the first time the variable is used.
- if error you can use
# Overview
- Object oriented
- 코드를 어떻게 오브젝트에 정리할 것인지 관건이다.
- Statically typed
- C style syntax
- Multiple environment
- 브라우저에서는 JS로 transpile, CL에서는 Dart VM으로 실행, 모바일에서는 머신코드로 컴파일 된다.
# Types
Every value has a type
Every variable has a type it can reference
Value vs Variable

Variable reference and pointed value must have same type
Once a variable has a type associated, the type cannot be changed
Dart can infer type :
vartype이String인지int인지 코드를 보고 유추한다.Dart can be dynamic : type을 다이나믹하게 할 수 있다.
# Why use types?
- Improved performance : 동적언어를 쓸때는 엔진이 체크를 하고 있다.
- Easier on large projects
- Less need of unit tests
- Find simple errors
# Built-in types
Numbers (opens new window) (
int,double)int64 bit numberdouble64 bit floating point number.- both are subtypes of
numand includes same basic operators. - converting to/from string to num
// String -> int var one = int.parse('1'); assert(one == 1); // String -> double var onePointOne = double.parse('1.1'); assert(onePointOne == 1.1); // int -> String String oneAsString = 1.toString(); assert(oneAsString == '1'); // double -> String String piAsString = 3.14159.toStringAsFixed(2); assert(piAsString == '3.14');1
2
3
4
5
6
7
8
9
10
11
12
13
14
15bit operation
assert((3 << 1) == 6); // 0011 << 1 == 0110 assert((3 | 4) == 7); // 0011 | 0100 == 0111 assert((3 & 4) == 0); // 0011 & 0100 == 00001
2
3
Strings (opens new window) (
String)# String interpolation
Booleans (opens new window) (
bool)Lists (opens new window) (
List, also known as arrays)Sets (opens new window) (
Set)Maps (opens new window) (
Map)Runes (opens new window) (
Runes; often replaced by thecharactersAPI)Symbols (opens new window) (
Symbol)The value
null(Null)
# Object Oriented Programming
- 오브젝트는
fields,properties라고 부르는 데이터와 오브젝트에 정의된methods라는 function으로 이루어진다. - 데이터는 오브젝트 외부에서는 가려져있고 메소드로만 접근할 수 있다.
- Class는 청사진이고 실제로 작동하는 object는 instance라고 한다.
← BuildContext Factory →