Fixes https://github.com/flutter/flutter/issues/147097. The expand/collapse icon should not be the disabled color when ExpansionPanel.canTapOnHeader is true because the ExpansionPanel is active, and we may want to keep the icon there as a visual indicator to the user that it is expandable/collapsable.
This commit is contained in:
@@ -363,6 +363,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
|
||||
margin: const EdgeInsetsDirectional.only(end: 8.0),
|
||||
child: ExpandIcon(
|
||||
color: widget.expandIconColor,
|
||||
disabledColor: child.canTapOnHeader ? widget.expandIconColor : null,
|
||||
isExpanded: _isChildExpanded(index),
|
||||
padding: _kExpandIconPadding,
|
||||
onPressed: !child.canTapOnHeader
|
||||
@@ -370,6 +371,7 @@ class _ExpansionPanelListState extends State<ExpansionPanelList> {
|
||||
: null,
|
||||
),
|
||||
);
|
||||
|
||||
if (!child.canTapOnHeader) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
expandIconContainer = Semantics(
|
||||
|
||||
@@ -1947,4 +1947,41 @@ void main() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('ExpandIcon.disabledColor uses expandIconColor color when canTapOnHeader is true', (WidgetTester tester) async {
|
||||
const Color expandIconColor = Color(0xff0000ff);
|
||||
|
||||
Widget buildWidget({ bool canTapOnHeader = false }) {
|
||||
return MaterialApp(
|
||||
home: SingleChildScrollView(
|
||||
child: ExpansionPanelList(
|
||||
expandIconColor: expandIconColor,
|
||||
children: <ExpansionPanel>[
|
||||
ExpansionPanel(
|
||||
canTapOnHeader: canTapOnHeader,
|
||||
headerBuilder: (BuildContext context, bool isExpanded) {
|
||||
return const ListTile(title: Text('Panel'));
|
||||
},
|
||||
body: const ListTile(title: Text('Content for Panel')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(buildWidget());
|
||||
|
||||
await tester.tap(find.text('Panel'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon));
|
||||
expect(expandIcon.disabledColor, isNull);
|
||||
|
||||
await tester.pumpWidget(buildWidget(canTapOnHeader: true));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expandIcon = tester.widget(find.byType(ExpandIcon));
|
||||
expect(expandIcon.disabledColor, expandIconColor);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user