Unverified Commit fd25dc84 authored by Sahaj Rana's avatar Sahaj Rana Committed by GitHub

Add 'mouseCursor' to TextFormField (#99822)

* Add 'mouseCursor' to TextFormField

Added 'mouseCursor' to TextFormField. 
Related issue: https://github.com/flutter/flutter/issues/99770

* added test for 'mouseCursor' in TextFormField.

added test for 'mouseCursor' in TextFormField.

* Update packages/flutter/test/material/text_form_field_test.dart
Co-authored-by: 's avatarTong Mu <dkwingsmt@users.noreply.github.com>

* Update packages/flutter/test/material/text_form_field_test.dart
Co-authored-by: 's avatarTong Mu <dkwingsmt@users.noreply.github.com>

* Minor update: Added a space.

* Removed icon & minor updates.
Co-authored-by: 's avatarTong Mu <dkwingsmt@users.noreply.github.com>
parent bcb9320d
...@@ -146,6 +146,7 @@ class TextFormField extends FormField<String> { ...@@ -146,6 +146,7 @@ class TextFormField extends FormField<String> {
ScrollController? scrollController, ScrollController? scrollController,
String? restorationId, String? restorationId,
bool enableIMEPersonalizedLearning = true, bool enableIMEPersonalizedLearning = true,
MouseCursor? mouseCursor,
}) : assert(initialValue == null || controller == null), }) : assert(initialValue == null || controller == null),
assert(textAlign != null), assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
...@@ -236,6 +237,7 @@ class TextFormField extends FormField<String> { ...@@ -236,6 +237,7 @@ class TextFormField extends FormField<String> {
autofillHints: autofillHints, autofillHints: autofillHints,
scrollController: scrollController, scrollController: scrollController,
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning, enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
mouseCursor: mouseCursor,
), ),
); );
}, },
......
...@@ -817,4 +817,69 @@ void main() { ...@@ -817,4 +817,69 @@ void main() {
final TextField textFieldWidget = tester.widget(textFieldFinder); final TextField textFieldWidget = tester.widget(textFieldFinder);
expect(textFieldWidget.scrollController, scrollController); expect(textFieldWidget.scrollController, scrollController);
}); });
testWidgets('TextFormField changes mouse cursor when hovered', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextFormField(
mouseCursor: SystemMouseCursors.grab,
),
),
),
),
);
// Center, which is within the area
final Offset center = tester.getCenter(find.byType(TextFormField));
// Top left, which is also within the area
final Offset edge = tester.getTopLeft(find.byType(TextFormField)) + const Offset(1, 1);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
await gesture.addPointer(location: center);
addTearDown(gesture.removePointer);
await tester.pump();
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
// Test default cursor
await tester.pumpWidget(
MaterialApp(
home: Material(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextFormField(),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
await gesture.moveTo(edge);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
await gesture.moveTo(center);
// Test default cursor when disabled
await tester.pumpWidget(
MaterialApp(
home: Material(
child: MouseRegion(
cursor: SystemMouseCursors.forbidden,
child: TextFormField(
enabled: false,
),
),
),
),
);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
await gesture.moveTo(edge);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
await gesture.moveTo(center);
});
} }
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