class _TextFieldDemoState extends State<TextFieldDemo> {
final _userName = TextEditingController();
var _isSelector = false;
int _sex = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('sss'),
),
body: Container(
child: Column(
children: <Widget>[
TextField(
decoration: const InputDecoration(
hintText: '用户名',
),
controller: _userName,
),
const SizedBox(
height: 10,
),
ElevatedButton(
onPressed: () {
print(_userName.text);
},
child: const Text('点我')),
Checkbox(
value: _isSelector,
onChanged: (v) {
setState(() {
_isSelector = v!;
});
}),
CheckboxListTile(
value: _isSelector,
secondary: Icon(Icons.help),
onChanged: (v) {
setState(() {
_isSelector = v!;
});
},
title: Text('标题'),
subtitle: Text('副标题'),
),
Row(
children: [
Radio(
value: 1,
groupValue: _sex,
onChanged: (v) {
setState(() {
_sex = v as int;
});
}),
Radio(
value: 2,
groupValue: _sex,
onChanged: (v) {
setState(() {
_sex = v as int;
});
}),
],
),
RadioListTile(
value: 1,
groupValue: _sex,
title: Text('321'),
subtitle: Text('321'),
onChanged: (v) {
setState(() {
_sex = v as int;
});
}),
RadioListTile(
value: 2,
groupValue: _sex,
title: Text('123'),
subtitle: Text('123'),
onChanged: (v) {
setState(() {
_sex = v as int;
});
}),
Switch(
value: _isSelector,
onChanged: (v){
setState(() {
_isSelector = v;
});
}
),
SwitchListTile(
value: _isSelector,
title: Text('aaaa'),
subtitle: Text('BBBB'),
onChanged: (v){
setState(() {
_isSelector = v;
});
}
),
SwitchListTile(
value: _isSelector,
title: Text('CCCC'),
subtitle: Text('DDDD'),
onChanged: (v){
setState(() {
_isSelector = v;
});
}
),
],
),
),
);
}
}