Unverified Commit f6747dfa authored by Justin Hutchins's avatar Justin Hutchins Committed by GitHub

Change cursor when hovering on DropdownButton (#80567)

parent 5bc34890
...@@ -19,6 +19,7 @@ import 'ink_well.dart'; ...@@ -19,6 +19,7 @@ import 'ink_well.dart';
import 'input_decorator.dart'; import 'input_decorator.dart';
import 'material.dart'; import 'material.dart';
import 'material_localizations.dart'; import 'material_localizations.dart';
import 'material_state.dart';
import 'scrollbar.dart'; import 'scrollbar.dart';
import 'shadows.dart'; import 'shadows.dart';
import 'theme.dart'; import 'theme.dart';
...@@ -1501,6 +1502,13 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -1501,6 +1502,13 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
); );
} }
final MouseCursor effectiveMouseCursor = MaterialStateProperty.resolveAs<MouseCursor>(
MaterialStateMouseCursor.clickable,
<MaterialState>{
if (!_enabled) MaterialState.disabled,
},
);
return Semantics( return Semantics(
button: true, button: true,
child: Actions( child: Actions(
...@@ -1509,6 +1517,8 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -1509,6 +1517,8 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
canRequestFocus: _enabled, canRequestFocus: _enabled,
focusNode: focusNode, focusNode: focusNode,
autofocus: widget.autofocus, autofocus: widget.autofocus,
child: MouseRegion(
cursor: effectiveMouseCursor,
child: GestureDetector( child: GestureDetector(
onTap: _enabled ? _handleTap : null, onTap: _enabled ? _handleTap : null,
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
...@@ -1516,6 +1526,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -1516,6 +1526,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
), ),
), ),
), ),
),
); );
} }
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' show window; import 'dart:ui' show window;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -3390,4 +3391,62 @@ void main() { ...@@ -3390,4 +3391,62 @@ void main() {
expect(feedback.hapticCount, 0); expect(feedback.hapticCount, 0);
}); });
}); });
testWidgets('DropdownButton changes mouse cursor when hovered', (WidgetTester tester) async {
const Key key = Key('testDropdownButton');
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DropdownButton<String>(
key: key,
onChanged: (String? newValue) {},
items: <String>['One', 'Two', 'Three', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList()
),
),
),
);
final Finder dropdownButtonFinder = find.byKey(key);
final Offset onDropdownButton = tester.getCenter(dropdownButtonFinder);
final Offset offDropdownButton = tester.getBottomRight(dropdownButtonFinder) + const Offset(1, 1);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: onDropdownButton);
addTearDown(gesture.removePointer);
await tester.pump();
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
await gesture.moveTo(offDropdownButton);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
// Test that mouse cursor doesn't change when button is disabled
await tester.pumpWidget(
MaterialApp(
home: Material(
child: DropdownButton<String>(
key: key,
items: <String>['One', 'Two', 'Three', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList()
),
),
),
);
await gesture.moveTo(onDropdownButton);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
await gesture.moveTo(offDropdownButton);
expect(RendererBinding.instance!.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment