Unverified Commit 995aa138 authored by Ayush Bherwani's avatar Ayush Bherwani Committed by GitHub

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

parent ba988f8c
...@@ -78,6 +78,7 @@ class ExpansionPanel { ...@@ -78,6 +78,7 @@ class ExpansionPanel {
required this.body, required this.body,
this.isExpanded = false, this.isExpanded = false,
this.canTapOnHeader = false, this.canTapOnHeader = false,
this.backgroundColor,
}) : assert(headerBuilder != null), }) : assert(headerBuilder != null),
assert(body != null), assert(body != null),
assert(isExpanded != null), assert(isExpanded != null),
...@@ -101,6 +102,10 @@ class ExpansionPanel { ...@@ -101,6 +102,10 @@ class ExpansionPanel {
/// Defaults to false. /// Defaults to false.
final bool canTapOnHeader; 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. /// An expansion panel that allows for radio-like functionality.
...@@ -123,11 +128,13 @@ class ExpansionPanelRadio extends ExpansionPanel { ...@@ -123,11 +128,13 @@ class ExpansionPanelRadio extends ExpansionPanel {
required ExpansionPanelHeaderBuilder headerBuilder, required ExpansionPanelHeaderBuilder headerBuilder,
required Widget body, required Widget body,
bool canTapOnHeader = false, bool canTapOnHeader = false,
Color? backgroundColor,
}) : assert(value != null), }) : assert(value != null),
super( super(
body: body, body: body,
headerBuilder: headerBuilder, headerBuilder: headerBuilder,
canTapOnHeader: canTapOnHeader, canTapOnHeader: canTapOnHeader,
backgroundColor: backgroundColor,
); );
/// The value that uniquely identifies a radio panel so that the currently /// The value that uniquely identifies a radio panel so that the currently
...@@ -530,6 +537,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> { ...@@ -530,6 +537,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
items.add( items.add(
MaterialSlice( MaterialSlice(
key: _SaltedKey<BuildContext, int>(context, index * 2), key: _SaltedKey<BuildContext, int>(context, index * 2),
color: child.backgroundColor,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
header, header,
......
...@@ -1458,4 +1458,75 @@ void main() { ...@@ -1458,4 +1458,75 @@ void main() {
' possible elevation values.' ' 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);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment