Flutter 다중 액션
Oct 14 2020
토글처럼 작동하는 '좋아요'버튼을 만들고 싶은데, 탭 동작으로 색상이 바뀌어 좋아요, 싫어하려면 다시 탭하세요. 어떻게 할 수 있습니까?
답변
6 Akif Oct 14 2020 at 14:21
다음과 같은 간단한 버튼을 사용할 수 있습니다.
IconButton(
onPressed: () {
setState(() {
_isLiked = !_isLiked;
});
}
},
icon: Icon(Constants.crownIcon,
color: _isLiked
? Constants.orangeColor
: Constants.ligthGreyColor,
size: 15.0,
),
),
1 Yeldar.N Oct 14 2020 at 14:18
ToggleButtons 를 사용할 수 있습니다.
ToggleButtons(
children: <Widget>[
Icon(Icons.ac_unit),
Icon(Icons.call),
Icon(Icons.cake),
],
onPressed: (int index) {
setState(() {
isSelected[index] = !isSelected[index];
});
},
isSelected: isSelected,
),