[ExpansionTile] Adds tilePadding property to ExpansionTile (#55221)
* Adds tilePadding property to ExpansionTile
This commit is contained in:
@@ -41,6 +41,7 @@ class ExpansionTile extends StatefulWidget {
|
||||
this.children = const <Widget>[],
|
||||
this.trailing,
|
||||
this.initiallyExpanded = false,
|
||||
this.tilePadding,
|
||||
}) : assert(initiallyExpanded != null),
|
||||
super(key: key);
|
||||
|
||||
@@ -80,6 +81,15 @@ class ExpansionTile extends StatefulWidget {
|
||||
/// Specifies if the list tile is initially expanded (true) or collapsed (false, the default).
|
||||
final bool initiallyExpanded;
|
||||
|
||||
/// Specifies padding for the [ListTile].
|
||||
///
|
||||
/// Analogous to [ListTile.contentPadding], this property defines the insets for
|
||||
/// the [leading], [title], [subtitle] and [trailing] widgets. It does not inset
|
||||
/// the expanded [children] widgets.
|
||||
///
|
||||
/// When the value is null, the tile's padding is `EdgeInsets.symmetric(horizontal: 16.0)`.
|
||||
final EdgeInsetsGeometry tilePadding;
|
||||
|
||||
@override
|
||||
_ExpansionTileState createState() => _ExpansionTileState();
|
||||
}
|
||||
@@ -165,6 +175,7 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
|
||||
textColor: _headerColor.value,
|
||||
child: ListTile(
|
||||
onTap: _handleTap,
|
||||
contentPadding: widget.tilePadding,
|
||||
leading: widget.leading,
|
||||
title: widget.title,
|
||||
subtitle: widget.subtitle,
|
||||
|
||||
@@ -229,4 +229,31 @@ void main() {
|
||||
|
||||
expect(find.text('Subtitle'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('ExpansionTile padding test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: ExpansionTile(
|
||||
title: Text('Hello'),
|
||||
tilePadding: EdgeInsets.fromLTRB(8, 12, 4, 10),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final Rect titleRect = tester.getRect(find.text('Hello'));
|
||||
final Rect trailingRect = tester.getRect(find.byIcon(Icons.expand_more));
|
||||
final Rect listTileRect = tester.getRect(find.byType(ListTile));
|
||||
final Rect tallerWidget = titleRect.height > trailingRect.height ? titleRect : trailingRect;
|
||||
|
||||
// Check the positions of title and trailing Widgets, after padding is applied.
|
||||
expect(listTileRect.left, titleRect.left - 8);
|
||||
expect(listTileRect.right, trailingRect.right + 4);
|
||||
|
||||
// Calculate the remaining height of ListTile from the default height.
|
||||
final double remainingHeight = 56 - tallerWidget.height;
|
||||
expect(listTileRect.top, tallerWidget.top - remainingHeight / 2 - 12);
|
||||
expect(listTileRect.bottom, tallerWidget.bottom + remainingHeight / 2 + 10);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user