Checkbox와 Switch

체크박스와 스위치는 사용법이 동일.
1 2 3 4 5 6 7 8 9 10 11 12 | var isChecked = false ; Checkbox(value: isChecked, onChanged: (value) { setState(() { isChecked = value!; }); }), Switch(value: isChecked, onChanged: (value) { setState(() { isChecked = value!; }); }), |
RadioListTile로 라디오버튼과 텍스트를 함께 선택하도록 하기

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | enum Answer { yes, no } class _MyHomePageState extends State<MyHomePage> { Map< int , Answer?> answerVal = {}; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: ListView.builder( itemCount: 10 , itemBuilder: (BuildContext context, int index) { return ListTile( contentPadding: const EdgeInsets.all( 16.0 ), title: const Text( '선택' ), subtitle: Padding( padding: const EdgeInsets.only(top: 8.0 ), child: Row( children: [ Expanded( child: RadioListTile<Answer>( title: const Text( '예' ), value: Answer.yes, groupValue: answerVal[index], onChanged: (Answer? value) { setState(() { answerVal[index] = value; }); }, ), ), Expanded( child: RadioListTile<Answer>( title: const Text( '아니오' ), value: Answer.no, groupValue: answerVal[index], onChanged: (Answer? value) { setState(() { answerVal[index] = value; }); }, ), ), ], ), ), ); }, ), ); } } |