[英]Flutter: CheckboxListTile remove default padding
更新: ListTitleTheme
需要使用 ListTitleTheme 。 contentPadding
现在是CheckboxListTile
的属性之一。 我们现在可以像这样删除默认padding
:
CheckboxListTile(
contentPadding: EdgeInsets.all(0),
)
尝试使用以下代码:
ListTileTheme(
contentPadding: EdgeInsets.all(0),
child: CheckboxListTile(
secondary: const Icon(Icons.drive_eta),
title: Text("Your message"),
onChanged: (bool value) {},
value: true,
),
),
添加
ListTileTheme(
contentPadding: EdgeInsets.all(0),
然后
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,
),
),
有几种方法:
Positioned
小部件的复选框(基本上是您自己的 CheckboxListTile 变体)custom_checkbox.dart
)中,找到他们添加 padding/margin 的部分,将其设置为 0。3)可以想象,所有这些方法都有其优点和缺点。
编辑
我为您创建了一个自定义复选框列表磁贴,其中填充要小得多。
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),
]);
}
}
如果您想使用该实现,请确保将checkboxTile
转换为无状态小部件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.