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

This commit is contained in:
Ayush Bherwani 2020-05-26 19:37:02 +05:30 committed by GitHub
parent 9d58a87066
commit b3434459d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -20,7 +20,7 @@ import 'theme_data.dart';
/// The [value], [onChanged], [activeColor] and [checkColor] properties of this widget are /// The [value], [onChanged], [activeColor] and [checkColor] properties of this widget are
/// identical to the similarly-named properties on the [Checkbox] widget. /// 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]. /// those of the same name on [ListTile].
/// ///
/// The [selected] property on this widget is similar to the [ListTile.selected] /// The [selected] property on this widget is similar to the [ListTile.selected]
@ -267,6 +267,7 @@ class CheckboxListTile extends StatelessWidget {
this.selected = false, this.selected = false,
this.controlAffinity = ListTileControlAffinity.platform, this.controlAffinity = ListTileControlAffinity.platform,
this.autofocus = false, this.autofocus = false,
this.contentPadding,
}) : assert(value != null), }) : assert(value != null),
assert(isThreeLine != null), assert(isThreeLine != null),
assert(!isThreeLine || subtitle != null), assert(!isThreeLine || subtitle != null),
@ -356,6 +357,14 @@ class CheckboxListTile extends StatelessWidget {
/// {@macro flutter.widgets.Focus.autofocus} /// {@macro flutter.widgets.Focus.autofocus}
final bool 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget control = Checkbox( final Widget control = Checkbox(
@ -392,6 +401,7 @@ class CheckboxListTile extends StatelessWidget {
onTap: onChanged != null ? () { onChanged(!value); } : null, onTap: onChanged != null ? () { onChanged(!value); } : null,
selected: selected, selected: selected,
autofocus: autofocus, autofocus: autofocus,
contentPadding: contentPadding,
), ),
), ),
); );

View file

@ -115,4 +115,33 @@ void main() {
expect(Focus.of(childKey.currentContext, nullOk: true).hasPrimaryFocus, isFalse); 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);
});
} }