티스토리 뷰
✅ 선택적 매개변수로 받기 _buildIcons
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(product.title, style: textTheme().bodyText1),
SizedBox(height: 4.0),
Text("${product.address} * ${product.publishedAt}"),
Text("${product.price}원", style: textTheme().headline2),
Row(
children: [
_buildIcons(iconDate: CupertinoIcons.chat_bubble_2, count: product.commentsCount),
_buildIcons(iconDate: CupertinoIcons.heart, count: product.heartCount),
],
)
],
);
}
Widget _buildIcons({required IconData iconDate, required int count}) {
//선택적 매개변수로 받기
return Row(
children: [
Icon(iconDate),
Text("${count}"),
],
);
}
➡ {required IconData iconDate, required int count}로 받아서 사용
✅ Visibility : 댓글 & 좋아요가 0이면 화면에 그리지 않기
➡ if-else문으로 해도 됨!
return Visibility(
visible: count > 0, //조건문
)
⭐ 컴포넌트화 할때는 순수하게 사용하기! (패딩도 사용 x)
✅ 숫자 관련된 util 파일 만들어서 사용하기 - INTL 라이브러리 사용
import 'package:intl/intl.dart';
String numberPriceFormat(String price) {
final formatter = NumberFormat("#,###원"); // INTL 라이브러리
return formatter.format(int.parse(price)); // 문자열을 숫자로 변경하는 함수
}
'- flutter' 카테고리의 다른 글
Widget 종류 (0) | 2022.11.21 |
---|---|
공통 AppBar 만들기 (0) | 2022.11.21 |
ListView - Divider / Image.network / CachedNetworkImage 라이브러리 (0) | 2022.11.21 |
code style 변경 (0) | 2022.11.18 |
Json 데이터로 DTO 생성하기 (0) | 2022.11.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 네트워크데이터
- table-calendar
- 네트워크로딩
- 플러터
- State
- 정렬변경
- Provider
- props
- 웹만들기
- 채팅리스트
- Flutter
- appbar
- 비동기
- 주사위게임
- throtting
- styled-components
- 모두의숙소
- 글쓰기
- GestureDetector
- hooks
- RadioList
- firestore
- 리액트문법
- useState
- Riverpod
- 리액트
- Filter
- map
- sort메서드
- react
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함