[Flutter/Dart] 기본 문법 정리

찌니·2022년 9월 27일
0

Flutter

목록 보기
1/13

플러터 시작....!!!!! 플러터는 매우 매우 처음이기 때문에 기본 문법부터 시작해봅시다
자바랑 비슷한듯 ~ 코틀린이랑 비슷한듯 ~ js 랑 비슷한듯 ~ 많은 언어랑 닮아서 헷갈리진 않을까 모르것네요

변수

타입은 앞에, var 사용시 타입 선언 x

String name = "zinkikixx";
var birth = 1110;

null-safety nullable과 non-nullable

String? nullable;
String nonNullable;

dynamic 변수

dynamic은 모든 형식을 허용한다, 기존 변수는 타입 변경이 허용되지 않지만 dynamic은 이후에 타입 변경시에도 오류가 나지 않음!

dynamic dy = 1;
dy = "apple" // 오류 안남

private 선언은 변수 이름 앞에 _를 붙이면 가능

String _priVar 
// private variable
// 클래스나 함수도 _를 붙히면 가능

immutable한 변수, final과 const

final과 const는 모두 한번 선언하면 변할 수 없는 상수 선언이지만 정의되는 타임에 따라 분명한 차이가 있다

  • final은 런타임 내에서 앱 실행시 정의
  • const는 앱 빌드시 정의 - rebulid 되지 않음

함수

기본함수 구조 : type + 함수명 + body

void hello(){
	print("hello");
}
String hello(){
	return "hello";

화살표 함수

String hello(String name) => 'hello $name!';

비동기

Future, async, await

void main(){
  futureFunc();
}

Future futureFunc() async{
  await Future.delayed(Duration(seconds : 3));
  print("hello");
  await Future.delayed(Duration(seconds : 3));
  print("hello");
  await Future.delayed(Duration(seconds : 3));
  print("hello");
}

위 코드는 3초마다 hello를 출력할것임

profile
찌니's develog

0개의 댓글