728x90
๋ฐ˜์‘ํ˜•
728x90

 

IntrinsicHeight class

์ด๋ฆ„์„ ๋ณด์ž๋งˆ์ž Intrinsic์ด ๋ฌด์Šจ ์˜๋ฏธ์ง€? ํ•˜๋Š” ์งˆ๋ฌธ์ด ์ƒ๊ฒผ๋‹ค.

์ฐพ์•„๋ณด๋‹ˆ Intrinsic๋Š” ๊ณ ์œ ํ•œ, ๋ณธ์งˆ์ ์ธ ์ด๋ผ๋Š” ๋œป์ด๋‹ค.

๋œป ๊ทธ๋Œ€๋กœ IntrinsicHeight๋Š” child์˜ ๊ณ ์œ  ๋†’์ด์— ๋งž์ถฐ child์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•˜๋Š” ์œ„์ ฏ์ด๋‹ค.

์ด ์œ„์ ฏ์€ ๋†’์ด๊ฐ€ ์ œํ•œ๋˜์ง€ ์•Š๊ณ  ๋ฌดํ•œ ํ™•์žฅ์„ ์‹œ๋„ํ•˜๋Š” child๋ฅผ ํ•„์š”๋กœ ํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค.

์ด ์œ„์ ฏ์ด child์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” constraints๋Š” ๋ถ€๋ชจ์˜ constraints๋ฅผ ์ง€ํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๋งŒ์•ฝ constraints๊ฐ€ child์˜ ์ตœ๋Œ€ ๊ณ ์œ  ๋†’์ด๋ฅผ ํฌํ•จํ•  ๋งŒํผ ์ถฉ๋ถ„ํžˆ ํฌ์ง€ ์•Š์œผ๋ฉด ๋น„๊ต์  ๋‚ฎ์€ ๋†’์ด๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค. ๋ฐ˜๋Œ€๋กœ, ์ตœ์†Œ ๋†’์ด constraints๊ฐ€ child์˜ ์ตœ๋Œ€ ๊ณ ์œ  ๋†’์ด๋ณด๋‹ค ํฌ๋ฉด ๋น„๊ต์  ๋” ๋งŽ์€ ๋†’์ด๊ฐ€ ์ง€์ •๋œ๋‹ค.

  • ๋ถ€๋ชจ์˜ constraints < child์˜ ๊ณ ์œ  ๋†’์ด
    ๋‚ฎ์€ ๋†’์ด๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.
  • ๋ถ€๋ชจ์˜ constraints > child์˜ ๊ณ ์œ  ๋†’์ด
    ๋†’์€ ๋†’์ด๋ฅผ ๊ฐ€์ง€๊ฒŒ ๋œ๋‹ค.

์ฆ‰, child๋Š” ๋ถ€๋ชจ์˜ constraints๋ฅผ ๋”ฐ๋ฅด๋Š”๋ฐ, constraints๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ด ๋•Œ ๋ถ€๋ชจ์˜ constraints์™€ child์˜ ๊ณ ์œ  ๋†’์ด ์‚ฌ์ด์˜ ๊ด€๊ณ„์— ๋Œ€ํ•œ ๊ฒƒ์ด๋‹ค.

๊ฐ€๋Šฅํ•œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

<์‚ฌ์šฉ ์ „>

<์‚ฌ์šฉ ํ›„>

 

 

728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

 

728x90
๋ฐ˜์‘ํ˜•
728x90
๋ฐ˜์‘ํ˜•
728x90

FractionallySizedBox class

FractionallySizedBox class๋Š” ์ƒ์œ„ ๋ถ€๋ชจ์˜ ์‚ฌ์ด์ฆˆ ๋น„์œจ์— ๋งž๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด๋‹ค.
์ฆ‰ ๋””์ž์ธ์˜ ํฌ๊ธฐ๊ฐ€ ์ƒ๋Œ€์ ์ด์–ด์•ผ ํ•  ๋•Œ ํฌ๊ธฐ๋ฅผ ์ƒ์œ„ ๋ถ€๋ชจ์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋น„์œจ๋กœ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

example)

  • FractionallySizedBox๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ƒ์œ„ ๋ถ€๋ชจ์˜ ์‚ฌ์ด์ฆˆ ๋น„์œจ์„ ์ง€์ •ํ•˜์—ฌ child์˜ ํฌ๊ธฐ๋ฅผ ์ •ํ•˜๊ณ  ์žˆ๋‹ค.
  • ์ฝ”๋“œ์—์„œ 0.7์€ 70%๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ฆ‰ ์ƒ์œ„ ๋ถ€๋ชจ ์‚ฌ์ด์ฆˆ์˜ 70%๋งŒํผ child๋ฅผ ๋งŒ๋“ค๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.
  • widthFactor์ฒ˜๋Ÿผ heightFactor์„ ์‚ฌ์šฉํ•˜์—ฌ ๋†’์ด์˜ ๋น„์œจ๋„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.


์ด์ฒ˜๋Ÿผ FractionallySizedBox class๋Š” ์ƒ์œ„ ๋ถ€๋ชจ์˜ ์‚ฌ์ด์ฆˆ ๋น„์œจ๋กœ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

 

๋ฐ˜์‘ํ˜•

 

728x90
๋ฐ˜์‘ํ˜•

'๐Ÿ’ง flutter' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Flutter] IntrinsicWidth class ์ •๋ฆฌ  (0) 2022.07.06
[Flutter] IntrinsicHeight class ์ •๋ฆฌ  (0) 2022.07.06
[Flutter] FittedBox Class ์ •๋ฆฌ  (0) 2022.07.06
[Flutter] CustomSingleChildLayout ์ •๋ฆฌ  (0) 2022.07.06
[Flutter] Initializer lists ์ •๋ฆฌ  (0) 2022.07.06
728x90
๋ฐ˜์‘ํ˜•

FittedBox Class

child ๋˜๋Š” ๋‚ด์šฉ์˜ ์–‘์— ๋”ฐ๋ผ ํฌ๊ธฐ๊ฐ€ ํ™•์žฅ๋˜๋Š” ์œ„์ ฏ์— ์˜ํ•ด ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒ๋˜๋Š” ๊ฒฝ์šฐ FittedBox๋กœ ๊ฐ์‹ธ๋ฉด ์ „์ฒด ํฌ๊ธฐ๋ฅผ ๋„˜์ง€ ์•Š๊ฒŒ ๋˜๋ฉฐ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐฉ์ง€๋œ๋‹ค.

alignment๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›ํ•˜๋Š” ๋ฐฐ์—ด๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค.

example)



์‚ฌ์šฉ ์ „)

์‚ฌ์šฉ ํ›„)

์ด์ฒ˜๋Ÿผ ๋ถ€๋ชจ์—์„œ ์ฃผ์–ด์ง„ ํฌ๊ธฐ ๋‚ด์— child๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

fittedBox๋Š” ๋ถ€๋ชจ ํฌ๊ธฐ์— ๋งž์ถฐ child ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
BoxFit.cover๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ถ€๋ชจ ํฌ๊ธฐ์— ๋”ฑ ๋งž๊ฒŒ child ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฐธ๊ณ ) https://medium.com/flutter-community/flutter-widgets-boxes-part-2-the-whole-picture-4bb142f0b1ab

728x90
๋ฐ˜์‘ํ˜•
728x90
๋ฐ˜์‘ํ˜•

CustomSingleChildLayout

childe์˜ ๋ ˆ์ด์•„์›ƒ์„ ์ง€์ •ํ•˜๋Š” ์œ„์ ฏ์ด๋‹ค.

  • delegate์€ child ๋ ˆ์ด์•„์›ƒ์˜ constraints๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ child๋ฅผ ์–ด๋””์— ๋‘˜์ง€, parent์˜ ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. ํ•˜์ง€๋งŒ parent๋Š” child์˜ ํฌ๊ธฐ์— ์˜์กดํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • CustomSingleChildLayout์€ delegate๋ฅผ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค.
  • ์ฃผ๋กœ grid๋ฅผ ๋งŒ๋“ค ๋•Œ ์“ฐ์ธ๋‹ค.

์ •๋ฆฌํ•˜๋ฉด, child์˜ ์œ„์น˜, ํฌ๊ธฐ๋ฅผ ๊ฒฐ์ •ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” layout ์ค‘ ํ•˜๋‚˜์ด๋‹ค.

 

example 1)

const CustomSingleChildLayout({
    Key key,
    @required this.delegate,
    Widget child,
  })

 

example 2)

Widget single(){
  return CustomSingleChildLayout(delegate: delegate)
}
728x90
๋ฐ˜์‘ํ˜•
728x90
๋ฐ˜์‘ํ˜•

Initializer lists

constructor ์‹คํ–‰ ์ „์— final fields๊ฐ€ ๊ฐ’์„ ๊ฐ€์ง€๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ๋“ฑ์˜ ์ดˆ๊ธฐ ์„ค์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ฆ‰, default field์— ์‹คํ–‰ ์ „์— ๊ฐ’์ด ์žˆ๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด Initializer lists์—์„œ ์ดˆ๊ธฐํ™” ํ•˜๋Š” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•œ๋‹ค.

Point.fromJson(Map<String, double> json)
    : x = json['x']!,
      y = json['y']! {
  print('In Point.fromJson(): ($x, $y)');
}

assert๋Š” ๊ฐœ๋ฐœ ๋ชจ๋“œ์˜ debug์ค‘์—๋งŒ ์˜ํ–ฅ์„ ๋ฏธ์นœ๋‹ค.
Initializer lists์—๋Š” ์ด๋ ‡๊ฒŒ debug์ค‘์—๋งŒ ์‹คํ–‰๋˜๋Š” assert๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค.

class FirstTwoLetters {
  final String letterOne;
  final String letterTwo;

  FirstTwoLetters(String word)
      : assert(word.length >= 2),
        letterOne = word[0],
        letterTwo = word[1];
}
  • ์ปดํ“จํ„ฐ๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค.

code example

class FirstTwoLetters {
  final String letterOne;
  final String letterTwo;

  // Create a constructor with an initializer list here:
  FirstTwoLetters(String word)
    ...
}

solution

class FirstTwoLetters {
  final String letterOne;
  final String letterTwo;

// Create a constructor with an initializer list here:
  FirstTwoLetters(String word)
      : assert(word.length >= 2),
        letterOne = word[0],
        letterTwo = word[1];
}

์ฐธ๊ณ  ์‚ฌ์ดํŠธ: https://dart.dev/codelabs/dart-cheatsheet#initializer-lists

 
728x90
๋ฐ˜์‘ํ˜•

+ Recent posts