티스토리 뷰

✅ 선택적 매개변수로 받기 _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
링크
«   2025/05   »
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
글 보관함