[英]Flutter: CheckboxListTile remove default padding
I'm looking to remove this padding around my row of CheckboxListTiles, but haven't found any information on how to do this without making my own version of a checkbox.我正在寻找在我的 CheckboxListTiles 行周围删除此填充,但没有找到有关如何在不制作我自己的复选框版本的情况下执行此操作的任何信息。
Is there any way to (using the CheckboxListTile):有什么办法(使用 CheckboxListTile):
UPDATE: THERE IS NOT NEED TO USE ListTitleTheme
ANYMORE .更新:
ListTitleTheme
需要使用 ListTitleTheme 。 contentPadding
is now one of CheckboxListTile
's properties. contentPadding
现在是CheckboxListTile
的属性之一。 We can now remove the default padding
like this:我们现在可以像这样删除默认
padding
:
CheckboxListTile(
contentPadding: EdgeInsets.all(0),
)
Try using the following code:尝试使用以下代码:
ListTileTheme(
contentPadding: EdgeInsets.all(0),
child: CheckboxListTile(
secondary: const Icon(Icons.drive_eta),
title: Text("Your message"),
onChanged: (bool value) {},
value: true,
),
),
Add添加
ListTileTheme(
contentPadding: EdgeInsets.all(0),
then然后
ListTileTheme(
contentPadding: EdgeInsets.all(0),
child: CheckboxListTile(
activeColor: CustomColors.purple,
title: Text("title text"),
value: true,
onChanged: (newValue) {},
controlAffinity:
ListTileControlAffinity.leading, // <-- leading Checkbox
),
),
contentPadding: EdgeInsets.all(0),
是不错的选择
ListTileTheme(
horizontalTitleGap: 0,
child: CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
title: Text(
title,
style: kRegularFontStyle.copyWith(
fontSize: 16.0.sp,
color: Theme.of(context).textTheme.subtitle1!.color,
),
),
value: isChecked,
onChanged: onChanged,
activeColor: kStructuralBlue500,
checkColor: kWhiteColor,
checkboxShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0.r)),
contentPadding: EdgeInsets.zero,
),
),
There are couple ways:有几种方法:
Positioned
widget (basically your own variation of CheckboxListTile)Positioned
小部件的复选框(基本上是您自己的 CheckboxListTile 变体)custom_checkbox.dart
), find the part where they added the padding/ margin, set it to 0. 3)custom_checkbox.dart
)中,找到他们添加 padding/margin 的部分,将其设置为 0。3) All of those approaches have its advantages and disadvantages as you can imagine.可以想象,所有这些方法都有其优点和缺点。
Edit编辑
I have created for you a custom checkbox list tile, where the padding is much smaller.我为您创建了一个自定义复选框列表磁贴,其中填充要小得多。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
color: Colors.grey,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
checkboxTile('Charger'),
checkboxTile('Bag'),
checkboxTile('Mouse'),
]),
),
),
);
}
Widget checkboxTile(String title) {
return Row(children: [
Text(title),
Checkbox(value: true, onChanged: (v) => null),
]);
}
}
Make sure to convert checkboxTile
into a stateless widget if you wanna use that implementation.如果您想使用该实现,请确保将
checkboxTile
转换为无状态小部件。
click here to see custom checkbox list tile as image单击此处查看自定义复选框列表磁贴作为图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.