diff --git a/packages/flutter/lib/src/material/checkbox_list_tile.dart b/packages/flutter/lib/src/material/checkbox_list_tile.dart index 410980423c..1a829f5d8c 100644 --- a/packages/flutter/lib/src/material/checkbox_list_tile.dart +++ b/packages/flutter/lib/src/material/checkbox_list_tile.dart @@ -20,7 +20,7 @@ import 'theme_data.dart'; /// The [value], [onChanged], [activeColor] and [checkColor] properties of this widget are /// identical to the similarly-named properties on the [Checkbox] widget. /// -/// The [title], [subtitle], [isThreeLine], and [dense] properties are like +/// The [title], [subtitle], [isThreeLine], [dense], and [contentPadding] properties are like /// those of the same name on [ListTile]. /// /// The [selected] property on this widget is similar to the [ListTile.selected] @@ -267,6 +267,7 @@ class CheckboxListTile extends StatelessWidget { this.selected = false, this.controlAffinity = ListTileControlAffinity.platform, this.autofocus = false, + this.contentPadding, }) : assert(value != null), assert(isThreeLine != null), assert(!isThreeLine || subtitle != null), @@ -356,6 +357,14 @@ class CheckboxListTile extends StatelessWidget { /// {@macro flutter.widgets.Focus.autofocus} final bool autofocus; + /// Defines insets surrounding the tile's contents. + /// + /// This value will surround the [Checkbox], [title], [subtitle], and [secondary] + /// widgets in [CheckboxListTile]. + /// + /// When the value is null, the `contentPadding` is `EdgeInsets.symmetric(horizontal: 16.0)`. + final EdgeInsetsGeometry contentPadding; + @override Widget build(BuildContext context) { final Widget control = Checkbox( @@ -392,6 +401,7 @@ class CheckboxListTile extends StatelessWidget { onTap: onChanged != null ? () { onChanged(!value); } : null, selected: selected, autofocus: autofocus, + contentPadding: contentPadding, ), ), ); diff --git a/packages/flutter/test/material/checkbox_list_tile_test.dart b/packages/flutter/test/material/checkbox_list_tile_test.dart index 18fa5746a3..5c0eb9b85d 100644 --- a/packages/flutter/test/material/checkbox_list_tile_test.dart +++ b/packages/flutter/test/material/checkbox_list_tile_test.dart @@ -115,4 +115,33 @@ void main() { expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); }); + testWidgets('CheckoxListTile contentPadding test', (WidgetTester tester) async { + await tester.pumpWidget( + wrap( + child: const Center( + child: CheckboxListTile( + value: false, + onChanged: null, + title: Text('Title'), + contentPadding: EdgeInsets.fromLTRB(10, 18, 4, 2), + ), + ), + ) + ); + + final Rect paddingRect = tester.getRect(find.byType(Padding)); + final Rect checkboxRect = tester.getRect(find.byType(Checkbox)); + final Rect titleRect = tester.getRect(find.text('Title')); + + final Rect tallerWidget = checkboxRect.height > titleRect.height ? checkboxRect : titleRect; + + // Check the offsets of CheckBox and title after padding is applied. + expect(paddingRect.right, checkboxRect.right + 4); + expect(paddingRect.left, titleRect.left - 10); + + // Calculate the remaining height from the default ListTile height. + final double remainingHeight = 56 - tallerWidget.height; + expect(paddingRect.top, tallerWidget.top - remainingHeight / 2 - 18); + expect(paddingRect.bottom, tallerWidget.bottom + remainingHeight / 2 + 2); + }); }