Unverified Commit 37cb7b7b authored by Ayush Bherwani's avatar Ayush Bherwani Committed by GitHub

[ExpansionPanelList] adds dividerColor property (#59641)

parent fe15d1e7
...@@ -230,6 +230,7 @@ class ExpansionPanelList extends StatefulWidget { ...@@ -230,6 +230,7 @@ class ExpansionPanelList extends StatefulWidget {
this.expansionCallback, this.expansionCallback,
this.animationDuration = kThemeAnimationDuration, this.animationDuration = kThemeAnimationDuration,
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
}) : assert(children != null), }) : assert(children != null),
assert(animationDuration != null), assert(animationDuration != null),
_allowOnlyOnePanelOpen = false, _allowOnlyOnePanelOpen = false,
...@@ -319,6 +320,7 @@ class ExpansionPanelList extends StatefulWidget { ...@@ -319,6 +320,7 @@ class ExpansionPanelList extends StatefulWidget {
this.animationDuration = kThemeAnimationDuration, this.animationDuration = kThemeAnimationDuration,
this.initialOpenPanelValue, this.initialOpenPanelValue,
this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding,
this.dividerColor,
}) : assert(children != null), }) : assert(children != null),
assert(animationDuration != null), assert(animationDuration != null),
_allowOnlyOnePanelOpen = true, _allowOnlyOnePanelOpen = true,
...@@ -363,6 +365,12 @@ class ExpansionPanelList extends StatefulWidget { ...@@ -363,6 +365,12 @@ class ExpansionPanelList extends StatefulWidget {
/// during expansion. /// during expansion.
final EdgeInsets expandedHeaderPadding; final EdgeInsets expandedHeaderPadding;
/// Defines color for the divider when [ExpansionPanel.isExpanded] is false.
///
/// If `dividerColor` is null, then [DividerThemeData.color] is used. If that
/// is null, then [ThemeData.dividerColor] is used.
final Color dividerColor;
@override @override
State<StatefulWidget> createState() => _ExpansionPanelListState(); State<StatefulWidget> createState() => _ExpansionPanelListState();
} }
...@@ -528,6 +536,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> { ...@@ -528,6 +536,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
return MergeableMaterial( return MergeableMaterial(
hasDividers: true, hasDividers: true,
dividerColor: widget.dividerColor,
children: items, children: items,
); );
} }
......
...@@ -13,12 +13,14 @@ class SimpleExpansionPanelListTestWidget extends StatefulWidget { ...@@ -13,12 +13,14 @@ class SimpleExpansionPanelListTestWidget extends StatefulWidget {
this.firstPanelKey, this.firstPanelKey,
this.secondPanelKey, this.secondPanelKey,
this.canTapOnHeader = false, this.canTapOnHeader = false,
this.expandedHeaderPadding this.expandedHeaderPadding,
this.dividerColor,
}) : super(key: key); }) : super(key: key);
final Key firstPanelKey; final Key firstPanelKey;
final Key secondPanelKey; final Key secondPanelKey;
final bool canTapOnHeader; final bool canTapOnHeader;
final Color dividerColor;
/// If null, the default [ExpansionPanelList]'s expanded header padding value is applied via [defaultExpandedHeaderPadding] /// If null, the default [ExpansionPanelList]'s expanded header padding value is applied via [defaultExpandedHeaderPadding]
final EdgeInsets expandedHeaderPadding; final EdgeInsets expandedHeaderPadding;
...@@ -45,6 +47,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State<SimpleExpansionPane ...@@ -45,6 +47,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State<SimpleExpansionPane
extendedState[_index] = !extendedState[_index]; extendedState[_index] = !extendedState[_index];
}); });
}, },
dividerColor: widget.dividerColor,
children: <ExpansionPanel>[ children: <ExpansionPanel>[
ExpansionPanel( ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) { headerBuilder: (BuildContext context, bool isExpanded) {
...@@ -1343,4 +1346,54 @@ void main() { ...@@ -1343,4 +1346,54 @@ void main() {
expect(box.size.height, equals(128.0)); // _kPanelHeaderCollapsedHeight + 80.0 (double padding) expect(box.size.height, equals(128.0)); // _kPanelHeaderCollapsedHeight + 80.0 (double padding)
expect(box.size.width, equals(736.0)); expect(box.size.width, equals(736.0));
}); });
testWidgets('ExpansionPanelList respects dividerColor', (WidgetTester tester) async {
const Color dividerColor = Colors.red;
await tester.pumpWidget(const MaterialApp(
home: SingleChildScrollView(
child: SimpleExpansionPanelListTestWidget(
dividerColor: dividerColor,
),
),
));
final DecoratedBox decoratedBox = tester.widget(find.byType(DecoratedBox).last);
final BoxDecoration decoration = decoratedBox.decoration as BoxDecoration;
// For the last DecoratedBox, we will have a Border.top with the provided dividerColor.
expect(decoration.border.top.color, dividerColor);
});
testWidgets('ExpansionPanelList.radio respects DividerColor', (WidgetTester tester) async {
const Color dividerColor = Colors.red;
await tester.pumpWidget(MaterialApp(
home: SingleChildScrollView(
child: ExpansionPanelList.radio(
dividerColor: dividerColor,
children: <ExpansionPanelRadio>[
ExpansionPanelRadio(
headerBuilder: (BuildContext context, bool isExpanded) {
return Text(isExpanded ? 'B' : 'A', key: const Key('firstKey'));
},
body: const SizedBox(height: 100.0),
value: 0,
),
ExpansionPanelRadio(
headerBuilder: (BuildContext context, bool isExpanded) {
return Text(isExpanded ? 'D' : 'C', key: const Key('secondKey'));
},
body: const SizedBox(height: 100.0),
value: 1,
),
],
),
),
));
final DecoratedBox decoratedBox = tester.widget(find.byType(DecoratedBox).last);
final BoxDecoration boxDecoration = decoratedBox.decoration as BoxDecoration;
// For the last DecoratedBox, we will have a Border.top with the provided dividerColor.
expect(boxDecoration.border.top.color, dividerColor);
});
} }
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