Skip to content

Commit fd25dc8

Browse files
SahajRanadkwingsmt
andauthored
Add 'mouseCursor' to TextFormField (#99822)
* Add 'mouseCursor' to TextFormField Added 'mouseCursor' to TextFormField. Related issue: flutter/flutter#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: Tong Mu <[email protected]> * Update packages/flutter/test/material/text_form_field_test.dart Co-authored-by: Tong Mu <[email protected]> * Minor update: Added a space. * Removed icon & minor updates. Co-authored-by: Tong Mu <[email protected]>
1 parent bcb9320 commit fd25dc8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/flutter/lib/src/material/text_form_field.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class TextFormField extends FormField<String> {
146146
ScrollController? scrollController,
147147
String? restorationId,
148148
bool enableIMEPersonalizedLearning = true,
149+
MouseCursor? mouseCursor,
149150
}) : assert(initialValue == null || controller == null),
150151
assert(textAlign != null),
151152
assert(autofocus != null),
@@ -236,6 +237,7 @@ class TextFormField extends FormField<String> {
236237
autofillHints: autofillHints,
237238
scrollController: scrollController,
238239
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
240+
mouseCursor: mouseCursor,
239241
),
240242
);
241243
},

packages/flutter/test/material/text_form_field_test.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,4 +817,69 @@ void main() {
817817
final TextField textFieldWidget = tester.widget(textFieldFinder);
818818
expect(textFieldWidget.scrollController, scrollController);
819819
});
820+
821+
testWidgets('TextFormField changes mouse cursor when hovered', (WidgetTester tester) async {
822+
await tester.pumpWidget(
823+
MaterialApp(
824+
home: Material(
825+
child: MouseRegion(
826+
cursor: SystemMouseCursors.forbidden,
827+
child: TextFormField(
828+
mouseCursor: SystemMouseCursors.grab,
829+
),
830+
),
831+
),
832+
),
833+
);
834+
835+
// Center, which is within the area
836+
final Offset center = tester.getCenter(find.byType(TextFormField));
837+
// Top left, which is also within the area
838+
final Offset edge = tester.getTopLeft(find.byType(TextFormField)) + const Offset(1, 1);
839+
840+
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
841+
await gesture.addPointer(location: center);
842+
addTearDown(gesture.removePointer);
843+
844+
await tester.pump();
845+
846+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.grab);
847+
848+
// Test default cursor
849+
await tester.pumpWidget(
850+
MaterialApp(
851+
home: Material(
852+
child: MouseRegion(
853+
cursor: SystemMouseCursors.forbidden,
854+
child: TextFormField(),
855+
),
856+
),
857+
),
858+
);
859+
860+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
861+
await gesture.moveTo(edge);
862+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
863+
await gesture.moveTo(center);
864+
865+
// Test default cursor when disabled
866+
await tester.pumpWidget(
867+
MaterialApp(
868+
home: Material(
869+
child: MouseRegion(
870+
cursor: SystemMouseCursors.forbidden,
871+
child: TextFormField(
872+
enabled: false,
873+
),
874+
),
875+
),
876+
),
877+
);
878+
879+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
880+
await gesture.moveTo(edge);
881+
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
882+
await gesture.moveTo(center);
883+
});
884+
820885
}

0 commit comments

Comments
 (0)