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

Add ExpansionTile.childrenPadding property (#57291)

parent b70301fe
...@@ -45,6 +45,7 @@ class ExpansionTile extends StatefulWidget { ...@@ -45,6 +45,7 @@ class ExpansionTile extends StatefulWidget {
this.tilePadding, this.tilePadding,
this.expandedCrossAxisAlignment, this.expandedCrossAxisAlignment,
this.expandedAlignment, this.expandedAlignment,
this.childrenPadding,
}) : assert(initiallyExpanded != null), }) : assert(initiallyExpanded != null),
assert(maintainState != null), assert(maintainState != null),
assert( assert(
...@@ -138,6 +139,11 @@ class ExpansionTile extends StatefulWidget { ...@@ -138,6 +139,11 @@ class ExpansionTile extends StatefulWidget {
/// When the value is null, the value of `expandedCrossAxisAlignment` is [CrossAxisAlignment.center]. /// When the value is null, the value of `expandedCrossAxisAlignment` is [CrossAxisAlignment.center].
final CrossAxisAlignment expandedCrossAxisAlignment; final CrossAxisAlignment expandedCrossAxisAlignment;
/// Specifies padding for [children].
///
/// When the value is null, the value of `childrenPadding` is [EdgeInsets.zero].
final EdgeInsetsGeometry childrenPadding;
@override @override
_ExpansionTileState createState() => _ExpansionTileState(); _ExpansionTileState createState() => _ExpansionTileState();
} }
...@@ -266,9 +272,12 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider ...@@ -266,9 +272,12 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
final Widget result = Offstage( final Widget result = Offstage(
child: TickerMode( child: TickerMode(
child: Column( child: Padding(
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center, padding: widget.childrenPadding ?? EdgeInsets.zero,
children: widget.children, child: Column(
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
children: widget.children,
),
), ),
enabled: !closed, enabled: !closed,
), ),
...@@ -280,6 +289,5 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider ...@@ -280,6 +289,5 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
builder: _buildChildren, builder: _buildChildren,
child: shouldRemoveChildren ? null : result, child: shouldRemoveChildren ? null : result,
); );
} }
} }
...@@ -424,4 +424,61 @@ void main() { ...@@ -424,4 +424,61 @@ void main() {
}); });
testWidgets('childrenPadding default value', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Material(
child: Center(
child: ExpansionTile(
title: const Text('title'),
children: <Widget>[
Container(height: 100, width: 100),
],
),
),
),
));
await tester.tap(find.text('title'));
await tester.pumpAndSettle();
final Rect columnRect = tester.getRect(find.byType(Column).last);
final Rect paddingRect = tester.getRect(find.byType(Padding).last);
// By default, the value of childrenPadding is EdgeInsets.zero, hence offset
// of all the edges from x-axis and y-axis should be equal for Padding and Column.
expect(columnRect.top, paddingRect.top);
expect(columnRect.left, paddingRect.left);
expect(columnRect.right, paddingRect.right);
expect(columnRect.bottom, paddingRect.bottom);
});
testWidgets('ExpansionTile childrenPadding test', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Material(
child: Center(
child: ExpansionTile(
title: const Text('title'),
childrenPadding: const EdgeInsets.fromLTRB(10, 8, 12, 4),
children: <Widget>[
Container(height: 100, width: 100),
],
),
),
),
));
await tester.tap(find.text('title'));
await tester.pumpAndSettle();
final Rect columnRect = tester.getRect(find.byType(Column).last);
final Rect paddingRect = tester.getRect(find.byType(Padding).last);
// Check the offset of all the edges from x-axis and y-axis after childrenPadding
// is applied.
expect(columnRect.left, paddingRect.left + 10);
expect(columnRect.top, paddingRect.top + 8);
expect(columnRect.right, paddingRect.right - 12);
expect(columnRect.bottom, paddingRect.bottom - 4);
});
} }
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