[ExpansionPanel] Exposes color property of MaterialSlice (#71657)

This commit is contained in:
Ayush Bherwani 2020-12-08 09:18:02 +05:30 committed by GitHub
parent ba988f8c9c
commit 995aa138cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 0 deletions

View file

@ -78,6 +78,7 @@ class ExpansionPanel {
required this.body,
this.isExpanded = false,
this.canTapOnHeader = false,
this.backgroundColor,
}) : assert(headerBuilder != null),
assert(body != null),
assert(isExpanded != null),
@ -101,6 +102,10 @@ class ExpansionPanel {
/// Defaults to false.
final bool canTapOnHeader;
/// Defines the background color of the panel.
///
/// Defaults to [ThemeData.cardColor].
final Color? backgroundColor;
}
/// An expansion panel that allows for radio-like functionality.
@ -123,11 +128,13 @@ class ExpansionPanelRadio extends ExpansionPanel {
required ExpansionPanelHeaderBuilder headerBuilder,
required Widget body,
bool canTapOnHeader = false,
Color? backgroundColor,
}) : assert(value != null),
super(
body: body,
headerBuilder: headerBuilder,
canTapOnHeader: canTapOnHeader,
backgroundColor: backgroundColor,
);
/// The value that uniquely identifies a radio panel so that the currently
@ -530,6 +537,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
items.add(
MaterialSlice(
key: _SaltedKey<BuildContext, int>(context, index * 2),
color: child.backgroundColor,
child: Column(
children: <Widget>[
header,

View file

@ -1458,4 +1458,75 @@ void main() {
' possible elevation values.'
));
});
testWidgets('ExpansionPanel.panelColor test', (WidgetTester tester) async {
const Color firstPanelColor = Colors.red;
const Color secondPanelColor = Colors.brown;
await tester.pumpWidget(
MaterialApp(
home: SingleChildScrollView(
child: ExpansionPanelList(
expansionCallback: (int _index, bool _isExpanded) {},
children: <ExpansionPanel>[
ExpansionPanel(
backgroundColor: firstPanelColor,
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('A');
},
body: const SizedBox(height: 100.0),
),
ExpansionPanel(
backgroundColor: secondPanelColor,
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('B');
},
body: const SizedBox(height: 100.0),
),
],
),
),
),
);
final MergeableMaterial mergeableMaterial = tester.widget(find.byType(MergeableMaterial));
expect((mergeableMaterial.children.first as MaterialSlice).color, firstPanelColor);
expect((mergeableMaterial.children.last as MaterialSlice).color, secondPanelColor);
});
testWidgets('ExpansionPanelRadio.backgroundColor test', (WidgetTester tester) async {
const Color firstPanelColor = Colors.red;
const Color secondPanelColor = Colors.brown;
await tester.pumpWidget(MaterialApp(
home: SingleChildScrollView(
child: ExpansionPanelList.radio(
children: <ExpansionPanelRadio>[
ExpansionPanelRadio(
backgroundColor: firstPanelColor,
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('A');
},
body: const SizedBox(height: 100.0),
value: 0,
),
ExpansionPanelRadio(
backgroundColor: secondPanelColor,
headerBuilder: (BuildContext context, bool isExpanded) {
return const Text('B');
},
body: const SizedBox(height: 100.0),
value: 1,
),
],
),
),
));
final MergeableMaterial mergeableMaterial = tester.widget(find.byType(MergeableMaterial));
expect((mergeableMaterial.children.first as MaterialSlice).color, firstPanelColor);
expect((mergeableMaterial.children.last as MaterialSlice).color, secondPanelColor);
});
}