Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- ARM
- MDP
- C++
- DART
- Got
- 백준
- Flutter
- llm을 활용 단어장 앱 개발일지
- Kaggle
- MATLAB
- BFS
- FastAPI
- Image Processing
- 파이토치 트랜스포머를 활용한 자연어 처리와 컴퓨터비전 심층학습
- pytorch
- Dreamhack
- 영상처리
- PCA
- fastapi를 사용한 파이썬 웹 개발
- BOF
- BAEKJOON
- study book
- bloc
- Stream
- Computer Architecture
- system hacking
- rao
- ML
- Algorithm
- Widget
Archives
- Today
- Total
Bull
[Flutter::Widget] 토글 스위치...? 토글 버튼? (ToggleButtons class) 본문
Software Framework/Flutter
[Flutter::Widget] 토글 스위치...? 토글 버튼? (ToggleButtons class)
Bull_ 2024. 8. 14. 20:46
이 깔끔하고 아름다운 토글형태의 선택버튼이 있는 이미지를 생각했지만 아는 건 쥐뿔만큼 없는 난 토글 스위치라는 단어 밖에 생각나지 않았다. 요즘 GPT도 멍청해져서 그냥 혼자 찾아보고 있다가 카톡 오픈채팅으로 질문을 물어보았다. 구현하라고 하면 구현할 수는 있겠지만 내장되어 있는 위젯을 사용하는 게 더 깔끔하기 때문에 찾아보았다.

좋은 답변들이 왔지만 결국 자문자답하였다 ㅋㅋ 도움을 주신 분들 감사합니다.
글을 쓴 이유?
그림과 같은 토글버튼의 존재를 몰랐기 때문에 기억하려고 적은 이유가 커서 이미 목적은 달성했다. 제목을 저렇게 지은 이유도 이 때문이다. ToggleButtons에 대한 설명은 문서를 보면되니까. 기본을 알려주는 교과서적인 정리는 시간이 될 때..? 근데 하나 적고 싶은 게 있다!
ToggleButtons 크기 조절 방법

간단하다. constraints 프로퍼티로 조정해주면 된다.
constraints: BoxConstraints(
minWidth: 75,
minHeight: 30,
maxHeight: 30,
maxWidth: 75,
),
이 부분도 내가 10에서 15분 정도 헤맸던 내용이다...
CODE
List<bool> isSelected = [true, false];
(...CODE...)
ToggleButtons(
borderRadius: BorderRadius.circular(50),
isSelected: isSelected,
fillColor: Colors.lightGreen,
selectedColor: Colors.white,
color: Colors.lightGreen,
selectedBorderColor: Colors.lightGreen,
borderColor: Colors.lightGreen,
constraints: BoxConstraints(
minWidth: 75,
minHeight: 30,
maxHeight: 30,
maxWidth: 75,
),
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: Center(
child: Text(
'캘린더',
style: TextStyle(fontSize: 14),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: Center(
child: Text(
'그래프',
style: TextStyle(fontSize: 14),
),
),
),
],
onPressed: (int index) {
setState(() {
for (int i = 0; i < isSelected.length; i++) {
isSelected[i] = i == index;
}
});
},
),'Software Framework > Flutter' 카테고리의 다른 글
| [Flutter] 플러터에서 마크다운 적용하기! (0) | 2024.08.18 |
|---|---|
| [Flutter::State] Bloc Repository의 역할 (with FastAPI) (0) | 2024.08.15 |
| [Flutter::Widget] Drawer icon 변경 방법! (0) | 2024.08.14 |
| [Flutter::Widget] Textfield Widget size 조절 방법! (0) | 2024.08.14 |
| [Flutter::Widget] TextField의 Border radius과 Background color를 fit하게 넣기 (0) | 2024.08.10 |