Daily UI

Shadow Box

flutter developer 2025. 1. 29. 21:32

๐ŸŽจ What I Designed

https://github.com/suojae/flutter_ui_lab/blob/main/lib/2025/01/29.dart

 

flutter_ui_lab/lib/2025/01/29.dart at main · suojae/flutter_ui_lab

Contribute to suojae/flutter_ui_lab development by creating an account on GitHub.

github.com


๐Ÿ”Ž  How I Made It

์‚ฌ์šฉ๋œ ์ฃผ์š” ์œ„์ ฏ: Container, BoxDecoration, BoxShadow

 

What is Container?

A container first surrounds the child with padding and then applies additional constraints to the padded extent 

์ปจํ…Œ์ด๋„ˆ๋Š” ์ž์‹์œ„์ ฏ์„ padding์œผ๋กœ ๋‘˜๋Ÿฌ์‹ผ๋‹ค. ํŒจ๋”ฉ์ด ์—†์œผ๋ฉด ์ž์‹์œ„์ ฏ์€ ์ปจํ…Œ์ด๋„ˆ๋ž‘ ๋”ฑ ๋ถ™๊ฒŒ๋œ๋‹ค. ๋จ„์•ฝ ์ œ์•ฝ์กฐ๊ฑด(constraint)์„ ์„ค์ •ํ•˜๋ฉด ํŒจ๋”ฉ์„ ํฌํ•จํ•œ ์˜์—ญ์— ์ œ์•ฝ์ด ๋“ค์–ด๊ฐ„๋‹ค.

 

During painting, the container first applies the given transform, then paints the decoration to fill the padded extent, then it paints the child, and finally paints the foregroundDecoration, also filling the padded extent.

์ปจํ…Œ์ดํ„ฐ๋Š” ํšŒ์ „, ํฌ๊ธฐ์กฐ์ •, ๊ธฐ์šธ์ด๊ธฐ๋“ฑ์˜ "๋ณ€ํ™˜(Transform)"์„ ๋จผ์ € ์ ์šฉํ›„ "์žฅ์‹(decoration)", ์ž์‹(child)", "์ „๊ฒฝ(ForegroundDecoration)"์„ ๊ทธ๋ฆฌ๋Š” ์ˆœ์„œ๋กœ ์ง„ํ–‰๋œ๋‹ค.

 

Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible.

์ปจํ…Œ์ด๋„ˆ๋Š” child๊ฐ€ ์—†์œผ๋ฉด ํ™”๋ฉด์„ ๊ฝ‰์ฑ„์šด๋‹ค.

 

By default, containers return false for all hit tests

๊ธฐ๋ณธ์ ์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋Š” ํžˆํŠธํ…Œ์ŠคํŠธ๋ฅผ ๋ฌด์‹œํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ๋งŒ์•ฝ ์•ˆ์— Color๊ฐ™์€ ํ•˜์œ„์œ„์ ฏ์ด ์žˆ์œผ๋ฉด ํ•˜์œ„์œ„์ ฏ์ด ํ„ฐ์น˜์ด๋ฒคํŠธ์— ๋ฐ˜์‘ํ•˜์—ฌ hittest=true ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

What is BoxDecoration?

An immutable description of how to paint a box

๋ฐ•์Šค๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ถˆ๋ณ€๊ฐ์ฒด๋กœ ํ•œ ๋ฒˆ ์ƒ์„ฑํ•˜๋ฉด ์ดํ›„ ๋‚ด์šฉ ๋ณ€๊ฒฝ ๋ถˆ๊ฐ€

 

The box has a border, a body, and may cast a boxShadow.

BoxDecoration ์€ "๊ฒฝ๊ณ„(Border)", "๋ชธํ†ต(Body)", "๊ทธ๋ฆผ์ž(BoxShadow)" ์„ธ๊ฐ€์ง€ ์ฃผ์š” ์š”์†Œ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

 

 

What is BoxShadow?

A shadow cast by a box.

BoxShadow๋Š” ๋ฐ•์Šค์œ„์ ฏ์— ๊ทธ๋ฆผ์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉฐ ๋ฐ•์Šค๊ฐ€ ๋– ์žˆ๋Š”๋“ฏํ•œ 3Dํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

BoxShadow can cast non-rectangular shadows if the box is non-rectangular.

๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ๊ฐํ˜• ๋ชจ์–‘์˜ ๊ทธ๋ฆผ์ž๋ฅผ ๋ณด์—ฌ์ฃผ์ง€๋งŒ ๋ฐ•์Šค์˜ ๋ชจ์–‘์ด ๋ณ€๊ฒฝ๋˜๋ฉด ๊ทธ๋ฆผ์ž๋„ ๊ทธ ๋ชจ์–‘์„ ๋”ฐ๋ผ๊ฐ„๋‹ค. 

 

This class is similar to CSS box-shadow.

CSS์ฒ˜์—„ ์ƒ‰์ƒ, ์œ„์น˜(offset), ํ๋ฆผ์ •๋„(Blur), ํ™•์žฅ์ •๋„(Spread)๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

 

Why is the boxShadow property an array?

BoxShadow๊ฐ€ ๋ฐฐ์—ด๋กœ ์ •์˜๋˜์–ด ์žˆ๋Š” ์ด์œ ๋Š” Container ์œ„์ ฏ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ทธ๋ฆผ์ž๋ฅผ ๋™์‹œ์ ์šฉํ•˜๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•จ์ด๋‹ค. ์œ„ ์ฝ”๋“œ์ฒ˜๋Ÿผ ๋นจ๊ฐ•/๊ฒ€์ •Shadow๊ฐ’์„ ๋ฐฐ์—ด์— ๋‹ด์•„์„œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ทธ๋ฆผ์ž๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

What's the difference between Container01 and Container02? - InnerBlur vs OuterBlur

 

ShadowBox01
- blurStyle: BlurStyle.inner๋Š” ๋‚ด๋ถ€ ํ๋ฆผ(Inner Blur) ํšจ๊ณผ๋ฅผ ์ ์šฉํ•œ๋‹ค.

- ์ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ทธ๋ฆผ์ž๊ฐ€ ๋ฐ•์Šค์˜ ์•ˆ์ชฝ์œผ๋กœ ํผ์ง€๊ฒŒ ํ•œ๋‹ค ์ด ๋ฐฉ์‹์€ ๋ฌผ๋ฆฌ์ ์ธ ๊ทธ๋ฆผ์ž๋ณด๋‹ค๋Š” ์กฐ๋ช…์— ์˜ํ•œ ๋ฐ˜์‚ฌ์ฒ˜๋Ÿผ ๋‚ด๋ถ€์ ์ธ, ๊ฐ„์ ‘์ ์ธ ๊ทธ๋ฆผ์ž ๋Š๋‚Œ์„ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

ShadowBox02

- blurRadius: 12์™€ spreadRadius: 4๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ทธ๋ฆผ์ž๋ฅผ ๋ฐ•์Šค ๋ฐ”๊นฅ์ชฝ์œผ๋กœ ํผ์ง€๊ฒŒ ๋งŒ๋“ ๋‹ค.

- ๊ทธ๋ฆผ์ž๊ฐ€ ๋ฐ•์Šค ์™ธ๋ถ€๋กœ ํ๋ฆฟํ•˜๊ฒŒ ํ™•์žฅ๋˜์–ด ์ž…์ฒด๊ฐ๊ณผ ๊นŠ์ด๋ฅผ ๊ฐ•์กฐํ•œ๋‹ค.

- spreadRadius๊ฐ€ 4๋กœ ์„ค์ •๋˜์–ด ๊ทธ๋ฆผ์ž๊ฐ€  ๋„“๊ฒŒ ํผ์ง€๋ฉฐ, ๊ทธ๋ผ๋ฐ์ด์…˜์ฒ˜๋Ÿผ ๋ณ€ํ•˜๋Š” ๊ทธ๋ฆผ์ž์˜ ๊ฐ€์žฅ์ž๋ฆฌ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

๋‘˜์˜ ์ฐจ์ด๋Š” ์™ธ๋ถ€/๋‚ด๋ถ€ ํ๋ฆผ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ๊ทธ๋ฆผ์ž๊ฐ€ ์–ด๋–ป๊ฒŒ ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์ฐจ์ด์ด๋‹ค. ๋‚ด๋ถ€ ํ๋ฆผ์€ ๋ฐ•์Šค๊ฐ€ ๋ฐ€ํ๋œ ๊ณต๊ฐ„์— ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ ๋งŒ๋“ค๊ณ , ์™ธ๋ถ€ ํ๋ฆผ์€ ๋ฌผ๋ฆฌ์ ์ธ 3D ๊ณต๊ฐ„์—์„œ ๊ทธ๋ฆผ์ž๊ฐ€ ์ฃผ๋ณ€ ํ™˜๊ฒฝ์— ์˜ํ•ด ์˜ํ–ฅ์„ ๋ฐ›๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๊ฒŒ ํ•œ๋‹ค.