mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
[ExpansionTile] adds collapsedBackgroundColor property (#69575)
This commit is contained in:
parent
d618b81075
commit
4019956fc8
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue