HIDI Flutter Challenge (4) SafeArea & Spacer & SizedBox Widget

hello_hidiยท2021๋…„ 8์›” 29์ผ
0

HIDI's Flutter Challenge

๋ชฉ๋ก ๋ณด๊ธฐ
4/12
post-thumbnail

SafeArea & Spacer & SizedBox Widget

> SafeArea

  • ์šด์˜ ์ฒด์ œ์˜ ์นจ์ž…์„ ํ”ผํ•˜๊ธฐ์— ์ถฉ๋ถ„ํ•œ ํŒจ๋”ฉ์œผ๋กœ ํ•˜์œ„ ํ•ญ๋ชฉ์„ ์‚ฝ์ž…ํ•˜๋Š” ์œ„์ ฏ
  • ์˜ˆ๋ฅผ ๋“ค์–ด, ํ™”๋ฉด ๋งจ ์œ„์— ์žˆ๋Š” ์ƒํƒœ ํ‘œ์‹œ์ค„์„ ํ”ผํ•  ์ˆ˜ ์žˆ์„ ๋งŒํผ ํ•˜์œ„ ํ•ญ๋ชฉ์ด ๋“ค์—ฌ์“ฐ๊ธฐ๋ฉ๋‹ˆ๋‹ค.
  • ์ตœ์†Œ ํŒจ๋”ฉ์ด ์ง€์ •๋˜๋ฉด ์ตœ์†Œ ํŒจ๋”ฉ ์ค‘ ๋” ํฐ ํŒจ๋”ฉ ๋˜๋Š” ์•ˆ์ „ ์˜์—ญ ํŒจ๋”ฉ์ด ์ ์šฉ
  • SafeArea์˜ ์œ„์ ฏ์ด MediaQuery๋ฅผ ํ†ตํ•ด ์•ฑ์˜ ์‹ค์ œ ํ™”๋ฉด ํฌ๊ธฐ๋ฅผ ๊ณ„์‚ฐํ•˜๊ณ  ์ด๋ฅผ ์˜์—ญ์œผ๋กœ ์‚ผ์•„ ๋‚ด์šฉ์„ ํ‘œ์‹œํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ž˜๋ฆฌ๊ฑฐ๋‚˜ ๊ฐ€๋ ค์ง€๋Š” ๋ถ€๋ถ„ ์—†์ด ์ „๋ถ€ ๋‚˜์˜ฌ์ˆ˜ ์žˆ๊ฒŒ ๋˜๋Š” ๊ฒƒ

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ƒํ™ฉ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

image

๋งจ ์•„๋ž˜์— ์žˆ๋Š” Text์˜ ๊ฒฝ์šฐ ์ž˜๋ฆฌ๊ฒŒ ๋˜์ฃ .

์ด ๋ถ€๋ถ„์„ SafeArea๋กœ ๊ฐ์‹ธ์ฃผ๊ฒŒ ๋˜๋ฉด

image

  
  const SafeArea({
    Key? key,
    this.left = true,
    this.top = true,
    this.right = true,
    this.bottom = true,
    this.minimum = EdgeInsets.zero,
    this.maintainBottomViewPadding = false,
    required this.child,
}) : assert(left != null),
     assert(top != null),
     assert(right != null),
     assert(bottom != null),
     super(key: key);
 
 

> Spacer

  • ํ–‰ ๋˜๋Š” ์—ด๊ณผ ๊ฐ™์€ Flex ์ปจํ…Œ์ด๋„ˆ์˜ ์œ„์ ฏ ๊ฐ„ ๊ฐ„๊ฒฉ์„ ์กฐ์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์กฐ์ • ๊ฐ€๋Šฅํ•œ ๋นˆ ์ŠคํŽ˜์ด์„œ๋ฅผ ๋งŒ๋“œ๋Š” ์œ„์ ฏ
  • Row์™€ Column ์œ„์ ฏ์—์„œ ๊ฐ€์žฅ ์ผ๋ฐ˜์ ์œผ๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค.

const Spacer({Key? key, this.flex = 1})
  : assert(flex != null),
    assert(flex > 0),
    super(key: key);

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

  • flex : ๊ณต๊ฐ„์„ ์–ผ๋งˆ๋‚˜ ์ฐจ์ง€ํ• ์ง€ ๊ฒฐ์ •ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ

>> ์˜ˆ์‹œ ์ฝ”๋“œ


Row(
    children: const [
      Text('Begin'),
      Spacer(), // Defaults to a flex of one.
      Text('Middle'),
      // Gives twice the space between Middle and End than Begin and Middle.
      Spacer(flex: 2),
      Text('End'),
    ],
  );

>> ์‹คํ–‰ ๊ฒฐ๊ณผ

image

begin๊ณผ middle ์‚ฌ์ด์— ๋‘๋ฐฐ๋งŒํผ middle๊ณผ end ์‚ฌ์ด๊ฐ€ ๋ฒŒ์–ด์ ธ์žˆ๋‹ค. => flex๊ฐ€ 2์ด๊ธฐ ๋•Œ๋ฌธ์ธ๋‹ค!


> SizedBox

  • ์ง€์ •๋œ ํฌ๊ธฐ์˜ ์ƒ์ž ์œ„์ ฏ
  • ์ •ํ™•ํ•œ ์‚ฌ์ด์ฆˆ๋กœ ํ•˜์œ„ ์š”์†Œ๊นŒ์ง€ ๊ฐ™์€ ์‚ฌ์ด์กฐ๋กœ ๋งŒ๋“ค์–ด์คŒ
  • ์œ„์ ฏ ๊ฐ„ ์—ฌ์œ ๊ณต๊ฐ„์„ ํ™•๋ณดํ•  ๋•Œ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
  • sizedBox.expand -> width, height => double.infinity
    
    const SizedBox({ Key? key, this.width, this.height, Widget? child })
      : super(key: key, child: child);
    
    

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

  • width, height : ๋ฐ•์Šค์˜ ๊ฐ€๋กœ, ์„ธ๋กœ ํฌ๊ธฐ
  • child : ๋‹จ์ผ ์œ„์ ฏ ๊ฐ€๋Šฅ
profile
์•ˆ๋‡ฝํฌ๋””

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