[Flutter] Initializer lists ์ •๋ฆฌ
ยท
๐Ÿ’ง flutter
Initializer lists constructor ์‹คํ–‰ ์ „์— final fields๊ฐ€ ๊ฐ’์„ ๊ฐ€์ง€๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ๋“ฑ์˜ ์ดˆ๊ธฐ ์„ค์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ฆ‰, default field์— ์‹คํ–‰ ์ „์— ๊ฐ’์ด ์žˆ๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด Initializer lists์—์„œ ์ดˆ๊ธฐํ™” ํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. Point.fromJson(Map json) : x = json['x']!, y = json['y']! { print('In Point.fromJson(): ($x, $y)'); } assert๋Š” ๊ฐœ๋ฐœ ๋ชจ๋“œ์˜ debug์ค‘์—๋งŒ ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค. Initializer lists์—๋Š” ์ด๋ ‡๊ฒŒ debug์ค‘์—๋งŒ ์‹คํ–‰๋˜๋Š” assert๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค. class FirstTwoLetters { final String letterOne; ..