
왕초보 플러터 앱개발 2-6 수강중입니다.
하트 아이콘 클릭 시 하트 색상 변경이 안되어 질문 드립니다.
클릭했을 때 클릭이 되고 있는 표시? 도 안 뜨고 색상 변경도 되지 않습니다.
onTap에 print 코드도 넣어보았는데 실행이 안되네요ㅜ
구글링도 해보았는데 어디가 문제인지를 몰라서 해결을 못하고 있습니다!
feed.dart의 코드입니다.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Feed extends StatefulWidget {
const Feed({
super.key,
});
@override
State<Feed> createState() => _FeedState();
}
class _FeedState extends State<Feed> {
bool isFavorite = false;
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
'https://cdn2.thecatapi.com/images/6bt.jpg',
width: 100,
height: 100,
fit: BoxFit.cover,
),
),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'M1 아이패드 프로 11형(3세대) 와이파이 128G 팝니다.',
style: TextStyle(
fontSize: 16,
color: Colors.black,
),
softWrap: false,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 2),
Text(
'봉천동 · 6분 전',
style: TextStyle(
fontSize: 12,
color: Colors.black45,
),
),
SizedBox(height: 4),
Text(
'100만원',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
Row(
children: [
Spacer(),
GestureDetector(
onTap: () {
setState(() {
isFavorite = !isFavorite;
});
},
child: Row(
children: [
Icon(
isFavorite
? CupertinoIcons.heart_fill
: CupertinoIcons.heart,
color: isFavorite ? Colors.pink : Colors.black,
size: 16,
),
Text(
'1',
style: TextStyle(color: Colors.black54),
),
],
),
)
],
),
],
),
),
],
);
}
}
