Flutter:如何删除复选框的多余填充(多个CheckboxListTile)?

时间:2020-09-29 23:39:50

标签: flutter checkboxlist

我正在尝试创建一个复选框列表,如下所示: my plan

我将CheckBoxListTiledensecontentPadding一起使用来删除所有可能的填充,这就是我所拥有的: my result

是否可以删除CheckBoxListTile之间的多余“填充”?

这是我的代码(一个复选框):

class Checklist extends StatefulWidget {
  Checklist({@required this.content});
  final String content;

  @override
  _ChecklistState createState() => _ChecklistState();
}

class _ChecklistState extends State<Checklist> {
  bool _checked = false;
  @override
  Widget build(BuildContext context) {
    return CheckboxListTile(
      contentPadding: EdgeInsets.all(0),
      //dense: true,
      title: Text(widget.content, style: TextStyle(color: kBlackColor),),
      value: _checked,
      onChanged: (bool value) {
        setState(() {
          _checked = value;
        });
      },
      controlAffinity: ListTileControlAffinity.leading,
      activeColor: kBlackColor,
    );
  }
}

多个复选框:

Column(
   children: [
      Checklist(content: 'Develop an app'),
      Checklist(content: 'Develop a good app'),
      Checklist(content: 'Develop a really good app'),
   ],
),

1 个答案:

答案 0 :(得分:0)

将您的CheckBox包裹在SizedBox中将调整复选框的填充大小

SizedBox(
    height: whatYouWant,
    width: whatYouWant,
    child: Checkbox(...),
 )

请检查以下解决方案:https://stackoverflow.com/a/59420505/11989529