HIDI Flutter Challenge (11) AspectRatio & ClipRRect Widget

hello_hidiΒ·2021λ…„ 8μ›” 31일
0

HIDI's Flutter Challenge

λͺ©λ‘ 보기
11/12
post-thumbnail

AspectRatio & ClipRRect Widget

> AspectRatio Widget

  • νŠΉμ • μ’…νš‘λΉ„λ‘œ μžμ‹ 크기λ₯Ό μ‘°μ •ν•˜λŠ” μœ„μ ―
  • 이미지λ₯Ό 화면에 ν‘œμ‹œν•  λ•ŒλŠ” λΉ„μœ¨λ‘œ ν‘œμ‹œν•˜λŠ” 것이 μ’‹λ‹€
  1. λ¨Όμ € λ ˆμ΄μ•„μ›ƒ μ œμ•½μ—μ„œ ν—ˆμš©λ˜λŠ” κ°€μž₯ 큰 λ„ˆλΉ„ μ‹œλ„
  2. μœ„μ ―μ˜ λ†’μ΄λŠ” λ„ˆλΉ„μ— μ§€μ •λœ κ°€λ‘œ μ„Έλ‘œ λΉ„μœ¨μ„ μ μš©ν•˜μ—¬ κ²°μ •λ˜λ©° λ„ˆλΉ„μ— λŒ€ν•œ 높이 λΉ„μœ¨λ‘œ ν‘œν˜„
  • ex) ν™”λ©΄ 넓이 450, 높이 1000μ—μ„œ λΉ„μœ¨μ„ 3/2 μΌλ•Œ μ΄λ―Έμ§€μ˜ ν¬κΈ°λŠ”
    1. κ°€μž₯ 큰 λ„ˆλΉ„ -> 이미지 넓이 450
    2. 3/2 λΉ„μœ¨ -> 450* 2/3 = 300 높이가 됨

>> Implementaion

   
 const AspectRatio({
   Key? key,
   required this.aspectRatio,
   Widget? child,
  }) : assert(aspectRatio != null),
     assert(aspectRatio > 0.0),
     // can't test isFinite because that's not a constant expression
     super(key: key, child: child);
     
     

>> AspectRatio μ£Όμš” 속성

  • aspectRatio : κ°€λ‘œ μ„Έλ‘œ ν™”λ©΄ λΉ„μœ¨ => final double aspectRatio;(required)
  • child : μžμ‹ ν•œκ°œλ§Œ κ°€λŠ₯ => final Widget? child;

> ClipRRect Widget

  • λ‘₯κ·Ό μ‚¬κ°ν˜•μ„ μ‚¬μš©ν•˜μ—¬ μžμ‹μ„ 자λ₯΄λŠ” μœ„μ ―
  • μœ„μ ―μ— shapeμ΄λ‚˜ decoration 속성이 μ—†λ‹€λ©΄ ClipRRectλ₯Ό μ΄μš©ν•˜μ—¬ λͺ¨μ„œλ¦¬μ— 곑선을 쀄 수 μž‡λ‹€.
  • Container μœ„μ ― 같은 경우 μ‚¬μš©ν•  ν•„μš” x
  • ClipOval, ClipPath λ“± ν…Œλ‘λ¦¬λ₯Ό κ΄€λ¦¬ν•˜λŠ” λ‹€λ₯Έ μœ„μ ―λ“€λ„ 있음

>> Implementation


const ClipRRect({
  Key? key,
  this.borderRadius = BorderRadius.zero,
  this.clipper,
  this.clipBehavior = Clip.antiAlias,
  Widget? child,
}) : assert(borderRadius != null || clipper != null),
     assert(clipBehavior != null),
     super(key: key, child: child);
 
 

>> ClipRRect μ£Όμš” 속성

  • borderRadius : λ‘₯κ·Ό λͺ¨μ„œλ¦¬μ˜ ν…Œλ‘λ¦¬ λ°˜μ§€λ¦„λ₯Ό μ„€μ •ν•˜λŠ” 속성 => final BorderRadius? borderRadius;
  • child : μžμ‹ ν•œκ°œλ§Œ κ°€λŠ₯ => final Widget? child;
profile
μ•ˆλ‡½ν¬λ””

0개의 λŒ“κΈ€