diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index c955cbc255..17c663a4b6 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -230,6 +230,7 @@ class ExpansionPanelList extends StatefulWidget { this.expansionCallback, this.animationDuration = kThemeAnimationDuration, this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, + this.dividerColor, }) : assert(children != null), assert(animationDuration != null), _allowOnlyOnePanelOpen = false, @@ -319,6 +320,7 @@ class ExpansionPanelList extends StatefulWidget { this.animationDuration = kThemeAnimationDuration, this.initialOpenPanelValue, this.expandedHeaderPadding = _kPanelHeaderExpandedDefaultPadding, + this.dividerColor, }) : assert(children != null), assert(animationDuration != null), _allowOnlyOnePanelOpen = true, @@ -363,6 +365,12 @@ class ExpansionPanelList extends StatefulWidget { /// during expansion. 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 State createState() => _ExpansionPanelListState(); } @@ -528,6 +536,7 @@ class _ExpansionPanelListState extends State { return MergeableMaterial( hasDividers: true, + dividerColor: widget.dividerColor, children: items, ); } diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index a34ab5ba6c..5fc8e060d3 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -13,12 +13,14 @@ class SimpleExpansionPanelListTestWidget extends StatefulWidget { this.firstPanelKey, this.secondPanelKey, this.canTapOnHeader = false, - this.expandedHeaderPadding + this.expandedHeaderPadding, + this.dividerColor, }) : super(key: key); final Key firstPanelKey; final Key secondPanelKey; final bool canTapOnHeader; + final Color dividerColor; /// If null, the default [ExpansionPanelList]'s expanded header padding value is applied via [defaultExpandedHeaderPadding] final EdgeInsets expandedHeaderPadding; @@ -45,6 +47,7 @@ class _SimpleExpansionPanelListTestWidgetState extends State[ ExpansionPanel( headerBuilder: (BuildContext context, bool isExpanded) { @@ -1343,4 +1346,54 @@ void main() { expect(box.size.height, equals(128.0)); // _kPanelHeaderCollapsedHeight + 80.0 (double padding) 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( + 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); + }); }