class CheckboxDemo extends StatefulWidget {
@override
_CheckboxDemoState createState() => _CheckboxDemoState();
}
class _CheckboxDemoState extends State<CheckboxDemo> {
bool _checkboxItemA = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Checkbox'), elevation: 0.0,),
body: Container(
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CheckboxListTile( // 带标签和图标的复选框
value: _checkboxItemA,
onChanged: (value) {
setState(() {
_checkboxItemA = value;
});
},
title: Text('Checkbox Item A'),
subtitle: Text('Description'),
secondary: Icon(Icons.bookmark), // 图标
selected: _checkboxItemA, // 控制标题和图标是否使用激活状态的颜色
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Checkbox( // 复选框
value: _checkboxItemA, // 复选框的值
onChanged: (value) { // 点按复选框的处理方法
setState(() {
_checkboxItemA = value;
});
},
activeColor: Colors.blue, // 勾选状态下复选框的颜色
)
],
)
],
),
),
);
}
}
网友评论