일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- ShareTechnote
- javascript
- 무선통신
- QA
- 앱개발
- Python
- 코딩테스트
- HTTP
- 테스트자동화
- DART
- 실무PT후기
- pytest
- 서평
- 감사일기
- LTE기초
- 웹ui자동화
- 코멘토
- Flutter
- 카카오API
- testautomationuniversity
- 백준
- 하이브리드앱테스트
- Selenium
- QA직무교육
- 코딩
- 자동화테스트
- QA자동화
- 코멘토실무PT
- QA자동화테스트
- HTML
- Today
- Total
오예남
[Flutter] Expanded 위젯으로 Overflowed By xx pixels 해결하기 본문
안녕하세요, 오예남 입니다.
오늘은 저번시간에 만들었던 ListView를 만들면서 발생한 Overflowed 현상을 해결하는 방법을 공유드리려고 합니다.
Flutter에서 자주 발생하는 문제인데, 보통 Row/Column 위젯을 사용할때 고정되지않은 크기의 자식위젯을 사용하면 스마트폰의 범위를 벗어나면서 에러가 발생합니다.
아래 사진처럼 UI상에서 오버플로가 발생했다는 노란색,검은색 줄무늬의 에러 표시를 볼 수 있습니다.
위 현상은 Flexible 이나 Expanded 위젯을 사용하면 쉽게 해결할 수 있습니다.
저는 아래와같이 Expanded 위젯으로 Column 위젯을 wraping하여 해결하였습니다.
ListView.builder(
itemBuilder: (context, index) {
return Card(
child: Padding(
padding: EdgeInsets.only(left: 10, right: 10),
child: Container(
child: Row(
children: [
Image.network(
data![index]['thumbnail'],
height: 100,
width: 100,
fit: BoxFit.contain,
),
SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${data![index]['title'].toString()}",
overflow: TextOverflow.ellipsis,
),
Text(
"게시자 : ${data![index]['author'].toString()}"),
Text(
"등록일 : ${data![index]['datetime'].toString()}"),
Text(
"재생시간 : ${data![index]['play_time'].toString()}"),
])),
],
),
),
),
);
},
itemCount: data!.length,
))),
Expanded 위젯은 고정된 크기의 위젯들을 먼저 배치하고 남은 자리를 사용하는 위젯이라고 생각하시면 편해요.
flex 기능을 사용하면 Expanded 위젯끼리 비율도 지정해줄 수 있습니다.
Expanded만 사용하면 범위를 넘어서는 Text가 두줄로 표시되는데, 한줄로 표시하기위해 overflow 기능도 추가로 사용하였습니다.
Expanded 위젯에 대한 공식문서도 첨부해드릴테니 참고 해주세요!
https://api.flutter.dev/flutter/widgets/Expanded-class.html
Expanded class - widgets library - Dart API
A widget that expands a child of a Row, Column, or Flex so that the child fills the available space. Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space along the main axis (e.g., horizontally for a Row or ve
api.flutter.dev
'Flutter' 카테고리의 다른 글
[Flutter] bottomNavigationBar 를 사용해서 화면 전환하기 (0) | 2021.12.22 |
---|---|
[Flutter] http 네트워크 통신 / 카카오 API 로 데이터 받아오기_2 (0) | 2021.12.20 |
[Flutter] http 네트워크 통신 / 카카오 API 로 데이터 받아오기 (0) | 2021.12.17 |
[Flutter] FontAwesome 아이콘 사용하기 (font_awesome_flutter) (0) | 2021.12.15 |
Flutter/Dart 앱 개발 독학하기 좋은 <모두가 할 수 있는 플러터 UI 입문> (0) | 2021.12.13 |