Skip to content

Commit 4019956

Browse files
[ExpansionTile] adds collapsedBackgroundColor property (flutter#69575)
1 parent d618b81 commit 4019956

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/flutter/lib/src/material/expansion_tile.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ExpansionTile extends StatefulWidget {
4646
this.expandedCrossAxisAlignment,
4747
this.expandedAlignment,
4848
this.childrenPadding,
49+
this.collapsedBackgroundColor,
4950
}) : assert(initiallyExpanded != null),
5051
assert(maintainState != null),
5152
assert(
@@ -85,6 +86,9 @@ class ExpansionTile extends StatefulWidget {
8586
/// The color to display behind the sublist when expanded.
8687
final Color? backgroundColor;
8788

89+
/// When not null, defines the background color of tile when the sublist is collapsed.
90+
final Color? collapsedBackgroundColor;
91+
8892
/// A widget to display instead of a rotating arrow icon.
8993
final Widget? trailing;
9094

@@ -261,7 +265,9 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
261265
_iconColorTween
262266
..begin = theme.unselectedWidgetColor
263267
..end = theme.accentColor;
264-
_backgroundColorTween.end = widget.backgroundColor;
268+
_backgroundColorTween
269+
..begin = widget.collapsedBackgroundColor
270+
..end = widget.backgroundColor;
265271
super.didChangeDependencies();
266272
}
267273

packages/flutter/test/material/expansion_tile_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,40 @@ void main() {
481481
expect(columnRect.bottom, paddingRect.bottom - 4);
482482
});
483483

484+
testWidgets('ExpansionTile.collapsedBackgroundColor', (WidgetTester tester) async {
485+
const Key expansionTileKey = Key('expansionTileKey');
486+
const Color backgroundColor = Colors.red;
487+
const Color collapsedBackgroundColor = Colors.brown;
488+
489+
await tester.pumpWidget(const MaterialApp(
490+
home: Material(
491+
child: ExpansionTile(
492+
key: expansionTileKey,
493+
title: Text('Title'),
494+
backgroundColor: backgroundColor,
495+
collapsedBackgroundColor: collapsedBackgroundColor,
496+
children: <Widget>[
497+
SizedBox(height: 100, width: 100),
498+
],
499+
),
500+
),
501+
));
502+
503+
BoxDecoration boxDecoration = tester.firstWidget<Container>(find.descendant(
504+
of: find.byKey(expansionTileKey),
505+
matching: find.byType(Container),
506+
)).decoration! as BoxDecoration;
507+
508+
expect(boxDecoration.color, collapsedBackgroundColor);
509+
510+
await tester.tap(find.text('Title'));
511+
await tester.pumpAndSettle();
512+
513+
boxDecoration = tester.firstWidget<Container>(find.descendant(
514+
of: find.byKey(expansionTileKey),
515+
matching: find.byType(Container),
516+
)).decoration! as BoxDecoration;
517+
518+
expect(boxDecoration.color, backgroundColor);
519+
});
484520
}

0 commit comments

Comments
 (0)