forked from firka/flutter
Add ExpansionTile.childrenPadding property (#57291)
This commit is contained in:
@@ -45,6 +45,7 @@ class ExpansionTile extends StatefulWidget {
|
||||
this.tilePadding,
|
||||
this.expandedCrossAxisAlignment,
|
||||
this.expandedAlignment,
|
||||
this.childrenPadding,
|
||||
}) : assert(initiallyExpanded != null),
|
||||
assert(maintainState != null),
|
||||
assert(
|
||||
@@ -138,6 +139,11 @@ class ExpansionTile extends StatefulWidget {
|
||||
/// When the value is null, the value of `expandedCrossAxisAlignment` is [CrossAxisAlignment.center].
|
||||
final CrossAxisAlignment expandedCrossAxisAlignment;
|
||||
|
||||
/// Specifies padding for [children].
|
||||
///
|
||||
/// When the value is null, the value of `childrenPadding` is [EdgeInsets.zero].
|
||||
final EdgeInsetsGeometry childrenPadding;
|
||||
|
||||
@override
|
||||
_ExpansionTileState createState() => _ExpansionTileState();
|
||||
}
|
||||
@@ -266,9 +272,12 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
|
||||
|
||||
final Widget result = Offstage(
|
||||
child: TickerMode(
|
||||
child: Column(
|
||||
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
|
||||
children: widget.children,
|
||||
child: Padding(
|
||||
padding: widget.childrenPadding ?? EdgeInsets.zero,
|
||||
child: Column(
|
||||
crossAxisAlignment: widget.expandedCrossAxisAlignment ?? CrossAxisAlignment.center,
|
||||
children: widget.children,
|
||||
),
|
||||
),
|
||||
enabled: !closed,
|
||||
),
|
||||
@@ -280,6 +289,5 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
|
||||
builder: _buildChildren,
|
||||
child: shouldRemoveChildren ? null : result,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user