Fix ExpandIcon color when ExpansionPanel.canTapOnHeader true (#147097) (#147098)

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:
Benji Farquhar
2024-05-10 03:35:07 +12:00
committed by GitHub
parent 607a3dad76
commit a5e0c2ffe7
2 changed files with 39 additions and 0 deletions

View File

@@ -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(

View File

@@ -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);
});
}