mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
[ExpansionPanelList] adds dividerColor property (#59641)
This commit is contained in:
parent
fe15d1e793
commit
37cb7b7b48
|
@ -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<StatefulWidget> createState() => _ExpansionPanelListState();
|
||||
}
|
||||
|
@ -528,6 +536,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
|
|||
|
||||
return MergeableMaterial(
|
||||
hasDividers: true,
|
||||
dividerColor: widget.dividerColor,
|
||||
children: items,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<SimpleExpansionPane
|
|||
extendedState[_index] = !extendedState[_index];
|
||||
});
|
||||
},
|
||||
dividerColor: widget.dividerColor,
|
||||
children: <ExpansionPanel>[
|
||||
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>[
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue