Unverified Commit b3434459 authored by Ayush Bherwani's avatar Ayush Bherwani Committed by GitHub

[CheckboxListTile] exposes contentPadding property of ListTile. (#57868)

parent 9d58a870
......@@ -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,
),
),
);
......
......@@ -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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment