Flutter提供的一个通用列表条目结构,为左中结构,尾部是一个CheckBox。相应位置可插入组件,可以很方便地应对特定的条目。

相关组件

Checkbox

CheckBoxListTile的基本表现如下

【secondary】: 左侧组件 【Widget】
【checkColor】: ✔️颜色 【Color】
【activeColor】: 选中时外框颜色 【Color】
【title】: 中间上组件 【Widget】
【subtitle】: 中间下组件 【Widget】
【onChanged】: 选中事件 【Function(bool)】
30.gif

  1. import 'package:flutter/material.dart';
  2. class CustomCheckBoxListTile extends StatefulWidget {
  3. @override
  4. _CustomCheckBoxListTileState createState() => _CustomCheckBoxListTileState();
  5. }
  6. class _CustomCheckBoxListTileState extends State<CustomCheckBoxListTile> {
  7. var _selected = false;
  8. @override
  9. Widget build(BuildContext context) {
  10. return Container(
  11. margin: EdgeInsets.all(10),
  12. color: Colors.grey.withAlpha(22),
  13. child: CheckboxListTile(
  14. value: _selected,
  15. checkColor: Colors.yellow,
  16. activeColor: Colors.orangeAccent,
  17. secondary: Image.asset("assets/images/icon_head.png"),
  18. title: Text("张风捷特烈"),
  19. subtitle: Text("@万花过尽知无物"),
  20. onChanged: (v) => setState(() => _selected = !_selected),
  21. ),
  22. );
  23. }
  24. }

CheckBoxListTile的选中效果

【selected】: 是否选中 【bool】
31.gif

import 'package:flutter/material.dart';
class SelectCheckBoxListTile extends StatefulWidget {
  @override
  _SelectCheckBoxListTileState createState() => _SelectCheckBoxListTileState();
}

class _SelectCheckBoxListTileState extends State<SelectCheckBoxListTile> {
  var _selected = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      color: Colors.grey.withAlpha(22),
      child: CheckboxListTile(
        value: _selected,
        selected: _selected,
        checkColor: Colors.yellow,
        activeColor: Colors.orangeAccent,
        secondary: Image.asset("assets/images/icon_head.png"),
        title: Text("张风捷特烈"),
        subtitle: Text("@万花过尽知无物"),
        onChanged: (v) => setState(() => _selected = !_selected),
      ),
    );
  }
}

CheckBoxListTile的密排属性

【dense】: 是否密排 【bool】
32.gif

import 'package:flutter/material.dart';
class DenseCheckBoxListTile extends StatefulWidget {
  @override
  _DenseCheckBoxListTileState createState() => _DenseCheckBoxListTileState();
}

class _DenseCheckBoxListTileState extends State<DenseCheckBoxListTile> {
  var _selected = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      color: Colors.grey.withAlpha(22),
      child: CheckboxListTile(
        value: _selected,
        dense: true,
        checkColor: Colors.yellow,
        activeColor: Colors.orangeAccent,
        secondary: Image.asset("assets/images/icon_head.png"),
        title: Text("张风捷特烈"),
        subtitle: Text("@万花过尽知无物"),
        onChanged: (v) => setState(() => _selected = !_selected),
      ),
    );
  }
}