[TIL] Day 40 Container & SelectableText

ํ˜„์„œยท2026๋…„ 1์›” 20์ผ

[TIL] Flutter 9๊ธฐ

๋ชฉ๋ก ๋ณด๊ธฐ
52/65
post-thumbnail

๐Ÿ“ ํŠœํ„ฐ๋‹˜๊ณผ Widget ๊ณต๋ถ€

โœ๏ธ Container

Container๋ž€?

Container๋Š” ๋ฐ•์Šค ๋ชจ๋ธ(Box Model) ๊ฐœ๋… ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์œ„์ ฏ
๋‚ด๋ถ€์— ์œ„์ ฏ์„ ๋‹ด๊ณ  ํฌ๊ธฐ, ํŒจ๋”ฉ, ๋งˆ์ง„, ์žฅ์‹ ๋“ฑ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค๋ชฉ์  ๋ฐ•์Šค ์—ญํ• ์„ ํ•จ
์ฃผ๋กœ ๋ ˆ์ด์•„์›ƒ, ์Šคํƒ€์ผ๋ง, ๋ฐฐ๊ฒฝ ์žฅ์‹ ์šฉ๋„๋กœ ์‚ฌ์šฉ

์ฃผ์š” ์†์„ฑ

์†์„ฑ์„ค๋ช…์˜ˆ์‹œ
childContainer ์•ˆ์— ๋‹ด์„ ์œ„์ ฏchild: Text('Hello')
width๊ฐ€๋กœ ํฌ๊ธฐwidth: 100
height์„ธ๋กœ ํฌ๊ธฐheight: 50
padding๋‚ด๋ถ€ ์—ฌ๋ฐฑpadding: EdgeInsets.all(8)
margin์™ธ๋ถ€ ์—ฌ๋ฐฑmargin: EdgeInsets.symmetric(horizontal: 16)
color๋ฐฐ๊ฒฝ์ƒ‰color: Colors.blue
decoration๋ฐ•์Šค ์žฅ์‹(์ƒ‰, ๊ทธ๋ฆผ์ž, ํ…Œ๋‘๋ฆฌ, ๊ทธ๋ผ๋ฐ์ด์…˜ ๋“ฑ)BoxDecoration(borderRadius: BorderRadius.circular(8))
alignmentchild ์œ„์น˜ ์กฐ์ •alignment: Alignment.center
constraints์ตœ์†Œ/์ตœ๋Œ€ ํฌ๊ธฐ ์ œํ•œBoxConstraints(minWidth: 50, maxWidth: 200)
transform2D ๋ณ€ํ˜•(ํšŒ์ „, ์ด๋™ ๋“ฑ)transform: Matrix4.rotationZ(0.1)

Container ์‚ฌ์šฉ ์˜ˆ์‹œ

Container(
  width: 150,
  height: 100,
  padding: EdgeInsets.all(12),
  margin: EdgeInsets.symmetric(horizontal: 16),
  alignment: Alignment.center,
  decoration: BoxDecoration(
    color: Colors.blueAccent,
    borderRadius: BorderRadius.circular(8),
    boxShadow: [
      BoxShadow(
        color: Colors.black26,
        blurRadius: 4,
        offset: Offset(2, 2),
      )
    ],
  ),
  child: Text(
    'Flutter Container',
    style: TextStyle(color: Colors.white),
  ),
)

Container๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด?

Padding(
  padding: const EdgeInsets.symmetric(horizontal: 16), // margin
  child: SizedBox(
    width: 150,
    height: 100,
    child: DecoratedBox(
      decoration: BoxDecoration(
        color: Colors.blueAccent,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.black26,
            blurRadius: 4,
            offset: Offset(2, 2),
          ),
        ],
      ),
      child: Padding(
        padding: const EdgeInsets.all(12), // padding
        child: Center(
          child: Text(
            'Container',
            style: TextStyle(color: Colors.white),
          ),
        ),
      ),
    ),
  ),
)

โœ๏ธ SelectableText

SelectableText๋ž€?

ํ…์ŠคํŠธ๋ฅผ ๋“œ๋ž˜๊ทธํ•ด์„œ ์„ ํƒ / ๋ณต์‚ฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์œ„์ ฏ
์ผ๋ฐ˜ Text ์œ„์ ฏ๊ณผ์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์€
์œ ์ € ์ธํ„ฐ๋ž™์…˜(์„ ํƒ, ๋ณต์‚ฌ) ๊ฐ€๋Šฅ ์—ฌ๋ถ€

SelectionArea๋ž€?

ํ•˜์œ„ ์œ„์ ฏ ์ „์ฒด๋ฅผ ํ•˜๋‚˜์˜ โ€œ์„ ํƒ ๊ฐ€๋Šฅํ•œ ์˜์—ญโ€์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋Š” ์œ„์ ฏ


๊ณต๋ถ€ ์†Œ๊ฐ

์˜ค๋Š˜๋„ ์—ด์‹œ๋ฏธ ํŒ€ํ”Œ์„ ํ–ˆ๋‹ค.. ํžˆํžˆ..

0๊ฐœ์˜ ๋Œ“๊ธ€