HIDI Flutter Challenge (9) Container Widget

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

HIDI's Flutter Challenge

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

Container Widget

> Container Widget

  • ๋นˆ ๋ฐ•์Šค ์œ„์ ฏ
  • BUT SizedBox์™€ ์ฐจ์ด์ ์€ ๋‚ด๋ถ€์— decoration ์†์„ฑ์ด ์žˆ์–ด ๋ฐ•์Šค๋ฅผ ๊พธ๋ฐ€ ์ˆ˜ ์žˆ๋‹ค.cf)SizedBox๋Š” ๋ณดํ†ต ๋งˆ์ง„์„ ์ค„ ๋•Œ ์‚ฌ์šฉ
  • ์ž์‹์ด ์—†๋Š” Container๋Š” ๊ฐ€๋Šฅํ•œ ํ•œ ๋ฐ•์Šค๋ฅผ ํฌ๊ฒŒ ๋งŒ๋“ค๋ ค๊ณ  ํ•จ
  • but ์ž์‹์ด ์žˆ๋Š” COntainer๋Š” ์ž์‹์˜ ํฌ๊ธฐ์— ๋งž๊ฒŒ ์กฐ์ •๋จ

>> Implementation

  
  Container({
    Key? key,
    this.alignment,
    this.padding,
    this.color,
    this.decoration,
    this.foregroundDecoration,
    double? width,
    double? height,
    BoxConstraints? constraints,
    this.margin,
    this.transform,
    this.transformAlignment,
    this.child,
    this.clipBehavior = Clip.none,
}) : assert(margin == null || margin.isNonNegative),
     assert(padding == null || padding.isNonNegative),
     assert(decoration == null || decoration.debugAssertIsValid()),
     assert(constraints == null || constraints.debugAssertIsValid()),
     assert(clipBehavior != null),
     assert(decoration != null || clipBehavior == Clip.none),
     assert(color == null || decoration == null,
       'Cannot provide both a color and a decoration\n'
       'To provide both, use "decoration: BoxDecoration(color: color)".',
     ),
     constraints =
      (width != null || height != null)
        ? constraints?.tighten(width: width, height: height)
          ?? BoxConstraints.tightFor(width: width, height: height)
        : constraints,
     super(key: key);
  
  

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

  • padding : ์žฅ์‹ ๋‚ด๋ถ€์— ์ƒˆ๊ธธ ๋นˆ ๊ณต๊ฐ„, child๋Š” padding ์•ˆ์— ๋ฐฐ์น˜ ๋จ => final EdgeInsetsGeometry? padding;
  • color : child ๋’ท ๋ฐฐ๊ฒฝ์ƒ‰ , ๊ทธ๋ผ๋ฐ์ด์…˜ ์ด๋ฏธ์ง€ ๊ฐ™์€ ๊ฒƒ์€ decoration์—์„œ ํ™œ์šฉ => final Color? color;
  • decoration : child๋ฅผ ์žฅ์‹ํ•˜๋Š” ์†์„ฑ => final BoxDecoration? decoratino;(์ฃผ๋กœ ์‚ฌ์šฉ)
  • width, height : container ๊ฐ€๋กœ ์„ธ๋กœ ํฌ๊ธฐ
  • constraints : ํ•˜์œ„ ํ•ญ๋ชฉ์— ์ ์šฉํ•  ์ถ”๊ฐ€ ์ œ์•ฝ ์กฐ๊ฑด => final BoxConstraints? constraints;
    1. ์ƒ์„ฑ์ž ํญ ๋ฐ ๋†’์ด ์ธ์ˆ˜ ๋“ฑ๋“ฑ
    2. ํŒจ๋”ฉ์€ ๊ตฌ์†์กฐ๊ฑด ์•ˆ์œผ๋กœ ๋“ค์–ด๊ฐ
  • child : ํ•œ ๊ฐœ์˜ ์œ„์ ฏ๋งŒ ๊ฐ€๋Šฅ => final Widget? child;
  • alignment : child ๋‚ด๋ถ€๋ฅผ ์ •๋ ฌ => final AlignmentGeometry? alignment;

> BoxDecoration

  • ์ƒ์ž๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ• ์ œ๊ณต

>> Implementation

  
  const BoxDecoration({
    this.color,
    this.image,
    this.border,
    this.borderRadius,
    this.boxShadow,
    this.gradient,
    this.backgroundBlendMode,
    this.shape = BoxShape.rectangle,
}) : assert(shape != null),
     assert(
       backgroundBlendMode == null || color != null || gradient != null,
       "backgroundBlendMode applies to BoxDecoration's background color or "
       'gradient, but no color or gradient was provided.',
     );
     
     

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

  • color : ์ƒ์ž์˜ ๋ฐฐ๊ฒฝ์„ ์ฑ„์šธ ์ƒ‰์ƒ => final Color? color;
    1. ์ƒ‰์ƒ์€ ์ƒ์ž ๋ชจ์–‘์œผ๋กœ ์ฑ„์›Œ์ง
  • image : ๋ฐฐ๊ฒฝ์ƒ‰ ๋˜๋Š” ๊ทธ๋ผ๋ฐ์ด์…˜ ์œ„์— ๊ทธ๋ฆด ์ด๋ฏธ์ง€ => final DecorationImage? image;
  • border : ํ…Œ๋‘๋ฆฌ๋ฅผ ๊ทธ๋ฆฌ๋Š” ์†์„ฑ => final BoxBorder? border;
    1. shape, borderRadius ์†์„ฑ์— ๋”ฐ๋ฅธ๋‹ค
  • borderRadius : ํ…Œ๋‘๋ฆฌ๋ฅผ ์–ผ๋งŒํผ ๋‘ฅ๊ธ€๊ฒŒ ๋งŒ๋“ค์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์†์„ฑ => final BorderRadiusGeometry? borderRadius;
    1. ๋ชจ์–‘์ด๋‚˜ ํ…Œ๋‘๋ฆฌ๊ฐ€ ์žฅ์‹๋œ Container์˜ child๋ฅผ ์ž˜๋ผ๋‚ด์ง€ ์•Š์Œ
  • shape : ๋ฐ•์Šค ๋ชจ์–‘์„ ๊ฒฐ์ •ํ•˜๋Š” ์œ„์ ฏ(circle,Recktangle) => final BoxShape shape;
    1. ๋ชจ์–‘์ด๋‚˜ ํ…Œ๋‘๋ฆฌ๊ฐ€ ์žฅ์‹๋œ Container์˜ child๋ฅผ ์ž˜๋ผ๋‚ด์ง€ ์•Š์Œ
profile
์•ˆ๋‡ฝํฌ๋””

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