From b01558c1cd707dbb431ff1fb5b505a1d7358e402 Mon Sep 17 00:00:00 2001 From: Benji Farquhar <26356162+BenjiFarquhar@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:09:18 +1300 Subject: [PATCH] Fix cursor on hover expand/collapse icon (#155207) (#155209) @TahaTesser Fix undesirable side effects of your refactor away from my solution to add `IgnorePointer` during your code review of my PR https://github.com/flutter/flutter/pull/147098. I don't have time to implement my whole initial fix a second time, and update the tests that were added to verify your disabled color change. The issue is resolved with only adding the IgnorePointer. See [155207](https://github.com/flutter/flutter/issues/155207). --- .../lib/src/material/expansion_panel.dart | 20 ++++++++--------- .../test/material/expansion_panel_test.dart | 22 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/flutter/lib/src/material/expansion_panel.dart b/packages/flutter/lib/src/material/expansion_panel.dart index eb5ded8a8f..50588b2fb4 100644 --- a/packages/flutter/lib/src/material/expansion_panel.dart +++ b/packages/flutter/lib/src/material/expansion_panel.dart @@ -391,16 +391,16 @@ class _ExpansionPanelListState extends State { Widget expandIconPadded = Padding( padding: const EdgeInsetsDirectional.only(end: 8.0), - child: ExpandIcon( - color: widget.expandIconColor, - disabledColor: child.canTapOnHeader ? widget.expandIconColor : null, - isExpanded: _isChildExpanded(index), - padding: _kExpandIconPadding, - splashColor: child.splashColor, - highlightColor: child.highlightColor, - onPressed: !child.canTapOnHeader - ? (bool isExpanded) => _handlePressed(isExpanded, index) - : null, + child: IgnorePointer( + ignoring: child.canTapOnHeader, + child: ExpandIcon( + color: widget.expandIconColor, + isExpanded: _isChildExpanded(index), + padding: _kExpandIconPadding, + splashColor: child.splashColor, + highlightColor: child.highlightColor, + onPressed: (bool isExpanded) => _handlePressed(isExpanded, index) + ), ), ); diff --git a/packages/flutter/test/material/expansion_panel_test.dart b/packages/flutter/test/material/expansion_panel_test.dart index 8df161448f..bf3cd53177 100644 --- a/packages/flutter/test/material/expansion_panel_test.dart +++ b/packages/flutter/test/material/expansion_panel_test.dart @@ -1271,6 +1271,7 @@ void main() { expect(tester.getSemantics(find.byKey(expandedKey)), matchesSemantics( label: 'Expanded', isButton: true, + isEnabled: true, isFocusable: true, hasEnabledState: true, hasTapAction: true, @@ -1281,6 +1282,7 @@ void main() { label: 'Collapsed', isButton: true, isFocusable: true, + isEnabled: true, hasEnabledState: true, hasTapAction: true, hasFocusAction: true, @@ -2019,19 +2021,17 @@ void main() { widget is InkWell && widget.onTap != null) ); - final InkWell inkWell = tester.widget(inkWellFinder); + final InkWell inkWell = tester.widget(inkWellFinder.first); expect(inkWell.splashColor, expectedSplashColor); expect(inkWell.highlightColor, expectedHighlightColor); }); - testWidgets('ExpandIcon.disabledColor uses expandIconColor color when canTapOnHeader is true', (WidgetTester tester) async { - const Color expandIconColor = Color(0xff0000ff); + testWidgets('ExpandIcon ignores pointer/tap events when canTapOnHeader is true', (WidgetTester tester) async { Widget buildWidget({ bool canTapOnHeader = false }) { return MaterialApp( home: SingleChildScrollView( child: ExpansionPanelList( - expandIconColor: expandIconColor, children: [ ExpansionPanel( canTapOnHeader: canTapOnHeader, @@ -2048,16 +2048,18 @@ void main() { await tester.pumpWidget(buildWidget()); - await tester.tap(find.text('Panel')); - await tester.pumpAndSettle(); + final Finder ignorePointerFinder = find.descendant( + of: find.byType(ExpansionPanelList), + matching: find.byType(IgnorePointer), + ).first; - ExpandIcon expandIcon = tester.widget(find.byType(ExpandIcon)); - expect(expandIcon.disabledColor, isNull); + final IgnorePointer ignorePointerFalse = tester.widget(ignorePointerFinder); + expect(ignorePointerFalse.ignoring, isFalse); await tester.pumpWidget(buildWidget(canTapOnHeader: true)); await tester.pumpAndSettle(); - expandIcon = tester.widget(find.byType(ExpandIcon)); - expect(expandIcon.disabledColor, expandIconColor); + final IgnorePointer ignorePointerTrue = tester.widget(ignorePointerFinder); + expect(ignorePointerTrue.ignoring, isTrue); }); }