[ExpansionTile] adds collapsedBackgroundColor property (#69575)

This commit is contained in:
Ayush Bherwani 2020-11-03 12:28:04 +05:30 committed by GitHub
parent d618b81075
commit 4019956fc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View file

@ -46,6 +46,7 @@ class ExpansionTile extends StatefulWidget {
this.expandedCrossAxisAlignment,
this.expandedAlignment,
this.childrenPadding,
this.collapsedBackgroundColor,
}) : assert(initiallyExpanded != null),
assert(maintainState != null),
assert(
@ -85,6 +86,9 @@ class ExpansionTile extends StatefulWidget {
/// The color to display behind the sublist when expanded.
final Color? backgroundColor;
/// When not null, defines the background color of tile when the sublist is collapsed.
final Color? collapsedBackgroundColor;
/// A widget to display instead of a rotating arrow icon.
final Widget? trailing;
@ -261,7 +265,9 @@ class _ExpansionTileState extends State<ExpansionTile> with SingleTickerProvider
_iconColorTween
..begin = theme.unselectedWidgetColor
..end = theme.accentColor;
_backgroundColorTween.end = widget.backgroundColor;
_backgroundColorTween
..begin = widget.collapsedBackgroundColor
..end = widget.backgroundColor;
super.didChangeDependencies();
}

View file

@ -481,4 +481,40 @@ void main() {
expect(columnRect.bottom, paddingRect.bottom - 4);
});
testWidgets('ExpansionTile.collapsedBackgroundColor', (WidgetTester tester) async {
const Key expansionTileKey = Key('expansionTileKey');
const Color backgroundColor = Colors.red;
const Color collapsedBackgroundColor = Colors.brown;
await tester.pumpWidget(const MaterialApp(
home: Material(
child: ExpansionTile(
key: expansionTileKey,
title: Text('Title'),
backgroundColor: backgroundColor,
collapsedBackgroundColor: collapsedBackgroundColor,
children: <Widget>[
SizedBox(height: 100, width: 100),
],
),
),
));
BoxDecoration boxDecoration = tester.firstWidget<Container>(find.descendant(
of: find.byKey(expansionTileKey),
matching: find.byType(Container),
)).decoration! as BoxDecoration;
expect(boxDecoration.color, collapsedBackgroundColor);
await tester.tap(find.text('Title'));
await tester.pumpAndSettle();
boxDecoration = tester.firstWidget<Container>(find.descendant(
of: find.byKey(expansionTileKey),
matching: find.byType(Container),
)).decoration! as BoxDecoration;
expect(boxDecoration.color, backgroundColor);
});
}