mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
[CheckboxListTile] exposes contentPadding property of ListTile. (#57868)
This commit is contained in:
parent
9d58a87066
commit
b3434459d5
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue