728x90
반응형
class _MarketOrderBookState extends State<MarketOrderBook> {
final _isSelected = [true, false, false];
}
child: ToggleButtons(
constraints: BoxConstraints.expand(
width: (constraints.maxWidth - 4) / 3),
color: Color(0xff8d8d8d),
fillColor: Color(0xff4063ae),
selectedColor: Color(0xffffffff),
children: [
Wrap(
children: [
Padding(
padding: const EdgeInsets.only(right: 2.0),
child: Icon(
Icons.monetization_on,
size: 20,
),
),
Text('A'),
],
),
Wrap(
children: [
Padding(
padding: const EdgeInsets.only(right: 2.0),
child: Icon(
Icons.monetization_on,
size: 20,
),
),
Text('B'),
],
),
Wrap(
children: [
Padding(
padding: const EdgeInsets.only(right: 2.0),
child: Icon(
Icons.monetization_on,
size: 20,
),
),
Text('C'),
],
)
],
isSelected: _isSelected,
onPressed: (int index) {
setState(
() {
for (int buttonIndex = 0;
buttonIndex < _isSelected.length;
buttonIndex++) {
if (buttonIndex == index) {
_isSelected[buttonIndex] = true;
} else {
_isSelected[buttonIndex] = false;
}
}
// _buttonsState[index] = !_buttonsState[index];
},
);
},
),
목표: press(터치했을 때) 이벤트가 있을 때 하나만 활성화되는 버튼을 만든다.
상태 클래스에 final로 버튼의 기본값이 되는 변수를 선언해 놓는다.
isSelected는 true, fasle의 List boolean 값을 갖고 있다.
반응형
'개발자의 공부방 > 모바일' 카테고리의 다른 글
Flutter] DropdownButton을 눌렀을 때 목록 크기를 맞추는 방법. (0) | 2022.03.15 |
---|---|
Flutter] DropdownButton으로 DropBox 구현하기 (0) | 2022.03.15 |
Flutter] FloatingActionButton에서 그림자 제거 (0) | 2022.03.14 |
Flutter] flutter 프로젝트 실행 크롬으로 뜨는 문제 (0) | 2022.02.01 |
Flutter] 기본 레이아웃 이해 (0) | 2022.01.25 |