체크박스 만들기
class _MyHomePageState extends State<MyHomePage> {
bool _isChecked = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Receive User Information'),
),
body: Checkbox(
value: _isChecked,
onChanged: (value) {
setState(() {
_isChecked = value!;
});
},
)
);
}
}

CheckboxListTile 구현하기
class _MyHomePageState extends State<MyHomePage> {
bool _isChecked = false;
bool _isChecked2 = false;
bool _isChecked3 = false;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Receive User Information'),
),
body: ListView(
children: [
CheckboxListTile(
title: Text('Test'),
value: _isChecked,
onChanged: (value) {
setState(() {
_isChecked = value!;
});
},
),
CheckboxListTile(
title: Text('Test2'),
value: _isChecked2,
onChanged: (value) {
setState(() {
_isChecked2 = value!;
});
},
),
CheckboxListTile(
title: Text('Test3'),
value: _isChecked3,
onChanged: (value) {
setState(() {
_isChecked3 = value!;
});
},
),
],
)
);
}
}

RadioListTile 구현하기
enum Language {cpp, python, dart}
class _MyHomePageState extends State<MyHomePage> {
Language _language = Language.cpp;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Receive User Information'),
),
body: ListView(
children: [
RadioListTile(
title: Text('C++'),
value: Language.cpp,
groupValue: _language,
onChanged: (value) {
setState(() {
_language = value!;
});
}
),
RadioListTile(
title: Text('Python'),
value: Language.python,
groupValue: _language,
onChanged: (value) {
setState(() {
_language = value!;
});
}
),
RadioListTile(
title: Text('Dart'),
value: Language.dart,
groupValue: _language,
onChanged: (value) {
setState(() {
_language = value!;
});
}
)
],
),
);
}
}

DropDownButton 구현하기
class _MyHomePageState extends State<MyHomePage> {
final _valueList = List.generate(10, (i) => 'Student $i');
var _selectedValue = 'Student 0';
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Receive User Information'),
),
body: Center(
child: DropdownButton(
value: _selectedValue,
items: _valueList.map( (student) => DropdownMenuItem(
value: student,
child: Text(student)
)
).toList(),
onChanged: (value) {
setState(() {
_selectedValue = value!;
});
},
),
),
);
}
}

TextField 구현해보기
class _MyHomePageState extends State<MyHomePage> {
final _heightController = TextEditingController();
final _weightController = TextEditingController();
String _obesity = 'Normal';
void dispose() { // Widget이 사라졌을 때 실행하는 함수
_heightController.dispose();
_weightController.dispose();
super.dispose();
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Receive User Information'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Height'
),
controller: _heightController,
keyboardType: TextInputType.number,
),
Container(
height: 20,
),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Weight'
),
controller: _weightController,
keyboardType: TextInputType.number,
),
Container(height: 20,),
Text(_obesity, style: TextStyle(fontSize: 20),),
Container(height: 20,),
ElevatedButton(onPressed: () {
setState(() {
var heightValue = double.parse(_heightController.text.trim());
var weightValue = double.parse(_weightController.text.trim());
if (weightValue / heightValue * heightValue > 25) {
_obesity = 'Obesity';
} else {
_obesity = 'Normal';
}
});
}, child: Text('Enter'))
],
)
),
),
);
}
}
