220v
젝무의 개발새발
220v
전체 방문자
오늘
어제
  • 분류 전체보기 (255)
    • AI (35)
      • ML, DL 학습 (30)
      • 논문 리뷰 (4)
      • 실습 및 프로젝트 (1)
    • Algorithm (145)
      • LeetCode (13)
      • 프로그래머스 (35)
      • 백준 (96)
      • 알고리즘, 문법 정리 (1)
    • Mobile, Application (17)
      • Flutter (10)
      • iOS, MacOS (7)
    • BackEnd (7)
      • Flask (1)
      • Node.js (5)
      • Spring, JSP..etc (1)
    • Web - FrontEnd (18)
      • JavaScript, JQuery, HTML, C.. (12)
      • React (6)
    • DataBase (1)
      • MySQL (1)
      • Firebase Firestore (0)
      • Supabase (0)
    • Git (1)
    • 기타 툴 및 오류 해결 (3)
    • 강의 (5)
      • Database (3)
      • 암호학 (2)
      • 알고리즘 (0)
    • 후기와 회고 (2)
    • 블로그 꾸미기 (1)
    • 일상과 이것저것 (20)
      • 맛집 (12)
      • 세상사는일 (4)
      • 도서리뷰 (1)
      • 이런저런 생각들 (잡글) (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • Priority Queue
  • two pointer
  • brute-Force
  • REACT
  • 다익스트라
  • 오블완
  • Backtracking
  • 프로그래머스
  • topological sort
  • 티스토리챌린지
  • binary search
  • Greedy
  • disjoint set
  • Dynamic Programming
  • bitmasking
  • Mathematics
  • top-down
  • union-find
  • 구현
  • simulation
  • Prefix Sum
  • Lis
  • Minimum Spanning Tree
  • IMPLEMENT
  • 백준
  • dp
  • BFS
  • dfs
  • implementation
  • 위상 정렬

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
220v

젝무의 개발새발

Mobile, Application/Flutter

[Flutter] Container 안에서 이미지 사이즈 원하는대로 조정하기

2022. 11. 12. 03:56

Container 안에 이미지를 넣어서 흰 배경에, 이미지가 작게 들어가도록 하고 싶었다.

그런데 자꾸 Container의 child인 이미지가 Container의 width, height를 따라가는 것이.. 문제였음(container를 꽉 채움)

Container(
  width: 130,
  height: 130,
  decoration: BoxDecoration(
    color: Colors.blue,		// 시각적으로 잘 보이도록 파란색으로 바꿈
    borderRadius: BorderRadius.circular(10),
  ),
  child: Image(
    image: AssetImage("assets/img/dummyPikachu.png"),
    width: 100,
    height: 100,
  ),
),

 

 

이런 식으로 나온다.

이렇게 되는 이유는, Container의 특성 때문인데,

Container는 Container에서 설정한 width, height 로 그 child Widget의 width 와 height 의 constraint를 설정해버린다.

위의 예시에서, 이미지의 width, height constraint는 130, 130이 되어 버림.

그렇기 때문에, Image Widget에서 설정한 width 와 height 는 무용지물이 되어 버리는 것이다.

 

이를 해결하려면, 이런 꼼수를 쓰면 된다.

Container(
  width: 130,
  height: 130,
  decoration: BoxDecoration(
    color: Colors.blue,
    borderRadius: BorderRadius.circular(10),
  ),
  child: Center(
    child: Image(
      image: AssetImage("assets/img/dummyPikachu.png"),
      width: 100,
      height: 100,
    ),
  ),
),

Image Widget을 Center Widget으로 감싸주면 됨.

 

그럼 원하는대로 잘 나온다.

 

Reference

https://github.com/flutter/flutter/issues/20847

    'Mobile, Application/Flutter' 카테고리의 다른 글
    • [Flutter] Warning: CocoaPods not installed. Skipping pod install. 오류
    • [Google Maps API, Flutter] Google Maps(Places) API에서 response 언어 한국어로 설정하기
    • [Flutter, Firebase] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly": 에러 (M1 Mac 환경)
    • [Flutter, Firebase] Pub installs executables into $HOME/.pub-cache/bin 에러 (Firebase CLI)
    220v
    220v
    DGU CSE 20 / Apple Developer Academy @ POSTECH 2nd Jr.Learner.

    티스토리툴바