[Flutter] Dropdown #Spinner
2024. 3. 29. 18:03ㆍdev/flutter
728x90
반응형
StupidHead에 들어가는 코드를 기록해둔다.
DropdownButton을 사용하였었고, 특징은 대표 'value'를 설정해주어야 한다.
그리고 각각의 DropdownMenuItem에 클릭했을 경우의 입력할 'value'를 설정해주어야 한다.
그럼, onChange에서 value값을 받아와서 이후 동작을 수행할 수 있다.
DropdownButton(
value: context.select((SettingProvider value) => value.tabIndex),
items: const [
DropdownMenuItem(value:0 ,child: Text("WiFi")),
DropdownMenuItem(value:1, child: Text("ID/PW")),
DropdownMenuItem(value:2, child: Text("Toilet")),
DropdownMenuItem(value:3, child: Text("Memo")),
],
onChanged: (int? value) async {
debugPrint("DropdownButton.. value:$value");
context.read<SettingProvider>().tabIndex = value ?? 0;
)
DropdownMenu 적용
FittedBox(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownMenu<int>(
width: 150.0,
textStyle: const TextStyle(fontSize: 24.0),
initialSelection: context.select((SettingProvider value) => value.tabIndex),
dropdownMenuEntries: const <DropdownMenuEntry<int>>[
DropdownMenuEntry<int>(value: 0, label: "WiFi"),
DropdownMenuEntry<int>(value: 1, label: "ID/PW"),
DropdownMenuEntry<int>(value: 2, label: "Toilet"),
DropdownMenuEntry<int>(value: 3, label: "Memo"),
],
onSelected: (int? value) async {
debugPrint("DropdownButton.. value:$value");
context.read<SettingProvider>().tabIndex = value ?? 0;
},
),
),
)
728x90
반응형
'dev > flutter' 카테고리의 다른 글
[Flutter] admob Banner 광고(AlertDialog) (0) | 2024.04.04 |
---|---|
[Flutter] Backpressed WillPopScope #pop (0) | 2024.04.03 |
[Flutter] AnimatedList (0) | 2024.03.06 |
[Flutter] TopNavigationBar(DefaultTabController), TabBar (0) | 2024.03.05 |
[Flutter] Package #pub.dev #Plugin #src (0) | 2024.02.22 |