var / dynamic
void main(){
print('Test');
var a = 10;
var str = 'Hello';
var b = 3.5;
var isMarried = false;
dynamic c = 10;
myPrint(10);
myPrint('Hello');
num d = 10;
}
myPrint(dynamic str){
}
final / const
void main(){
final a = 10;
const b = 20;
}
List
void main(){
List<String> items = ['a','b','c'];
print(items);
print(items[0]);
print(items[1]);
}
Map, ...
void main(){
var items = [1,2,3];
var itemSet = {1,2,3};
print(itemSet);
var itemMap = {
'key': 'value',
'key1': 1,
'key2': 2,
'key3': 3,
}
print(itemMap);
var items2 = [...items,4,5];
print(items2);
}
method
void main(){
somethingMethod('name');
}
void somethingMethod(String name,{int age}){
print(name);
}
is
void main(){
var a = 10;
if(a is int){
print('정수');
}else if(a is! int){
print('정수가 아님');
}
var b = 3.5;
b = a as double;
var name;
print(name);
print(name ?? '널')
String name;
print(name?.toLowerCase());
}
class
void main(){
var person = Person('홍길동',age : 10);
}
class Person{
String name;
int age;
Person(this.name, {this.age});
}
비동기
void main(){
print ('시작');
networkRequest();
print('끝');
}
Future networkRequest() async{
print('네트워크 요청 시작');
await Feture.delayed(Duration(seconds:1));
print('네트워크 요청 끝');
}