class _FeedState extends State<Feed> {
bool isFavorite = false; // 좋아요 여부
...
}
GestureDetector(
// 위젯을 버튼처럼 만들 수 있음
onTap: () {
setState(() {
isFavorite = !isFavorite;
});
},
...
)
Icon(
isFavorite
? CupertinoIcons.heart_fill
: CupertinoIcons.heart,
color: isFavorite ? Colors.pink : Colors.black,
size: 16,
)
ListView(
children: [
Text("0"),
Text("1"),
Text("2"),
...
]
)
ListView.builder(
itemCount: 100, // 전체 아이템 개수
itemBuilder: (context, index) { // index는 0~99
return Text("$index");
}
)
ListView.separated(
itemCount: images.length,
itemBuilder: (context, index) {
return Feed();
},
separatorBuilder: (context, index) {
return Divider();
},
)
Feed Widget에 imageUrl 변수 생성
class Feed extends StatefulWidget {
const Feed({
Key? key,
required this.imageUrl,
}) : super(key: key);
final String imageUrl;
...
}
Image.network에 받아온 imageUrl 넣어주기
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.network(
widget.imageUrl,
width: 100,
height: 100,
fit: BoxFit.cover,
),
)
ListView.separated(
itemCount: images.length,
itemBuilder: (context, index) {
final image = images[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Feed(imageUrl: image),
);
},
...
)