Flutter - Row and Column (Expanded & Flexible Widget)

2023. 5. 29. 20:45·📘 Frontend/Flutter

Row and Colume (Expanded & Flexible Widget)

Expanded와 Flexible 위젯은 무조건 Colume이나 Row 위젯의 Children 에만 사용이 가능합니다.

이전에 만들었던 HomeScreen의 하위 컨테이너에 Expanded를 적용해 보겠습니다.

Expanded(  
  child: Container(  
    color: Colors.red,  
    width: 50.0,  
    height: 50.0,  
  ),

img


4개의 하위 컨테이너 중 맨위의 컨테이너에 적용해보니, 남은 여백을 전부 채워주는것을 볼 수 있습니다.

이번엔 2번째 컨테이너도 적용해 보겠습니다.

Expanded(  
  child: Container(  
    color: Colors.red,  
    width: 50.0,  
    height: 50.0,  
  ),  
),  
Expanded(  
  child: Container(  
    color: Colors.orange,  
    width: 50.0,  
    height: 50.0,  
  ),  
),

img


4개의 컨테이너 중 2개를 적용하니 남은 여백을 서로 절반씩 나눠 차지합니다.

그리고 Expanded의 파라미터 중 flex가 있습니다.

이 flex의 기본값은 1이며 만약 맨위 빨간 컨테이너에 flex 값을 2를 준다면

빨강 2 : 주황 1 의 비율로 여백을 차지합니다.


이제 4개의 컨테이너를 모두 Expanded로 바꾸고나서 맨위의 1개만 Flexible로 바꿔 봅시다.

Flexible은 1 만큼의 flex를 차지하되, Container의 width, height의 값만큼 차지하고 남는 부분은 여백으로 두는 기능이 있습니다.

img


위 사진을 보면 원래 컨테이너의 width, height 값인 50.0 만 차지하고,

남는 부분은 검은색 여백으로 버리는 것을 볼 수 있습니다.

Flexible의 flex 파라미터는 위와 동일하지만 flex 값이 커질수록 여백의 크기가 커진다는 차이점이 있습니다.

그리고 큰 특징 중 하나는, Expanded가 아무리 커도 Flexible의 여백을 차지할 수 없습니다.

저작자표시 (새창열림)

'📘 Frontend > Flutter' 카테고리의 다른 글

Flutter - Web View (프로젝트 세팅)  (0) 2023.05.29
Flutter - Row and Column 활용하여 실습  (0) 2023.05.29
Flutter - Row and Column (CrossAxisAlignment)  (0) 2023.05.29
Flutter - Row and Column (MainAxisAlignment)  (0) 2023.05.29
Flutter - Row and Column (Safe Area)  (0) 2023.05.29
'📘 Frontend/Flutter' 카테고리의 다른 글
  • Flutter - Web View (프로젝트 세팅)
  • Flutter - Row and Column 활용하여 실습
  • Flutter - Row and Column (CrossAxisAlignment)
  • Flutter - Row and Column (MainAxisAlignment)
신건우
신건우
조용한 개발자
  • 신건우
    우주먼지
    신건우
  • 전체
    오늘
    어제
    • 분류 전체보기 (422)
      • 📘 Frontend (71)
        • Markup (1)
        • Style Sheet (2)
        • Dart (8)
        • Javascript (12)
        • TypeScript (1)
        • Vue (36)
        • React (2)
        • Flutter (9)
      • 📘 Backend (143)
        • Java (34)
        • Concurrency (19)
        • Reflection (1)
        • Kotlin (29)
        • Python (1)
        • Spring (42)
        • Spring Cloud (5)
        • Message Broker (5)
        • Streaming (2)
        • 기능 개발 (5)
      • 💻 Server (6)
        • Linux (6)
      • ❌ Error Handling (11)
      • 📦 Database (62)
        • SQL (31)
        • NoSQL (2)
        • JPQL (9)
        • QueryDSL (12)
        • Basic (4)
        • Firebase (4)
      • ⚙️ Ops (57)
        • CS (6)
        • AWS (9)
        • Docker (8)
        • Kubernetes (13)
        • MSA (1)
        • CI & CD (20)
      • 📚 Data Architect (48)
        • Data Structure (10)
        • Algorithm (8)
        • Programmers (17)
        • BaekJoon (5)
        • CodeUp (4)
        • Design Pattern (4)
        • AI (0)
      • ⚒️ Management & Tool (8)
        • Git (7)
        • IntelliJ (1)
      • 📄 Document (10)
        • Project 설계 (6)
        • Server Migration (3)
      • 📄 책읽기 (2)
        • 시작하세요! 도커 & 쿠버네티스 (2)
      • 🎮 Game (4)
        • Stardew Vally (1)
        • Path of Exile (3)
  • 블로그 메뉴

    • 링크

      • Github
    • 공지사항

    • 인기 글

    • 태그

      Lock #Thread #Concurrency
      React #Markdown
      GStreamer #Pipeline
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    신건우
    Flutter - Row and Column (Expanded & Flexible Widget)
    상단으로

    티스토리툴바