浅识Flutter 基本组件之CheckboxListTile组件
CheckboxListTile的使用方法、功能和Checkbox差不多,但是它的使用范围更广、设计出的UI更美观
CheckboxListTile常用属性如下表所示。
属性名 | 类型 | 功能说明 |
---|---|---|
title | widget | 设置主标题组件 |
subtitle | Widget | 设置副标题组件 |
isThreeLine | bool | 设置显示的复选框是否占三行,默认值为false |
dense | bool | 设置是否垂直密集显示标题 |
secondary | widget | 设置显示的小组件,与□所在位置相反 |
selected | bool | 设置选中后标题文字高亮,默认值为 false |
controlAffinity | ListTileControlAffinity | 设置□相对于标题文字的位置,取值包含leading(前面)、platform (后面)和trailing(后面) |
CheckboxListTile的属性值
const CheckboxListTile({
Key? key,
required this.value,
required this.onChanged,
this.activeColor,
this.checkColor,
this.tileColor,
this.title,
this.subtitle,
this.isThreeLine = false,
this.dense,
this.secondary,
this.selected = false,
this.controlAffinity = ListTileControlAffinity.platform,
this.autofocus = false,
this.contentPadding,
this.tristate = false,
this.shape,
this.selectedTileColor,
this.visualDensity,
this.focusNode,
this.enableFeedback,
}) : assert(tristate != null),
assert(tristate || value != null),
assert(isThreeLine != null),
assert(!isThreeLine || subtitle != null),
assert(selected != null),
assert(controlAffinity != null),
assert(autofocus != null),
super(key: key);
必须要有value,onChanged
CheckboxListTile(onChanged: (bool? value) {
}, value:false,),
controlAffinity 设置□相对于标题文字的位置,取值包含leading(前面)、platform (后面)和trailing(后面)
/*调整复选框和图标的位置*/
controlAffinity:ListTileControlAffinity.leading ,
设置前
设置后:
创建多个CheckboxListTile
Column column = Column(
children: <Widget>[
CheckboxListTile(
value: this.isChecked,
/*设置主标题组件*/
title: Text(
'全选',
style: TextStyle(color: Colors.red)