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.
Is there any way to (using the CheckboxListTile):
UPDATE: THERE IS NOT NEED TO USE ListTitleTheme
ANYMORE . contentPadding
is now one of CheckboxListTile
's properties. We can now remove the default padding
like this:
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)custom_checkbox.dart
), find the part where they added the padding/ margin, set it to 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.