kyuyoungheo / flutter-study

0 stars 0 forks source link

Dart은 어떻게 옵셔널을 언래핑하지? #5

Open kyuyoungheo opened 4 months ago

kyuyoungheo commented 4 months ago

옵셔널을 어떻게 구현했고 어떤 종류의 언래핑 방법이 있지?

kyuyoungheo commented 4 months ago

Nullable 문서의 이 목차가 도움이 됨 https://dart.dev/null-safety/understanding-null-safety#working-with-nullable-types

Swift like guard, if let 구문은 없고 if(foo != null) 로만 사용하는 듯 Kotlin like Elvis Operator도 없음

Optional Chaining은 있음

na-young-kwon commented 4 months ago

언래핑 방법

  1. ? 있음
  2. ?? 있음
  3. ! 있음 (null 이면 런타임 에러 발생)
  4. 옵셔널 언래핑 없음
kyuyoungheo commented 4 months ago

답변 감사! 추가로 dart nullable operator 발견해서 공유함!

https://medium.com/flutter-community/null-aware-operators-281c18407afe

https://www.darttutorial.org/dart-tutorial/dart-null-aware-operators/

na-young-kwon commented 4 months ago

오 ??= 이거 신기하네요

na-young-kwon commented 4 months ago

삼항 연산자 가능 isDone ? Colors.red : Colors.blue 굿

kyuyoungheo commented 4 months ago

삼항 연산자 가능

isDone ? Colors.red : Colors.blue

굿

삼항연산자는 프로그래밍 언어라면 당연히 있어야... ㅋㅋㅋㅋ