@@ -701,6 +701,73 @@ void main() {
701
701
expect (tester.takeException (), null );
702
702
});
703
703
704
+ testWidgets ("Drag the floating cursor, it won't blink." , (WidgetTester tester) async {
705
+ const String text = 'hello world this is fun and cool and awesome!' ;
706
+ controller.text = text;
707
+ final FocusNode focusNode = FocusNode ();
708
+
709
+ await tester.pumpWidget (
710
+ MediaQuery (
711
+ data: const MediaQueryData (),
712
+ child: Directionality (
713
+ textDirection: TextDirection .ltr,
714
+ child: FocusScope (
715
+ node: focusScopeNode,
716
+ autofocus: true ,
717
+ child: EditableText (
718
+ backgroundCursorColor: Colors .grey,
719
+ controller: controller,
720
+ focusNode: focusNode,
721
+ style: textStyle,
722
+ cursorColor: cursorColor,
723
+ ),
724
+ ),
725
+ ),
726
+ ),
727
+ );
728
+
729
+ final EditableTextState editableText = tester.state (find.byType (EditableText ));
730
+
731
+ // Check that the cursor visibility toggles after each blink interval.
732
+ // Or if it's not blinking at all, it stays on.
733
+ Future <void > checkCursorBlinking ({ bool isBlinking = true }) async {
734
+ bool initialShowCursor = true ;
735
+ if (isBlinking) {
736
+ initialShowCursor = editableText.cursorCurrentlyVisible;
737
+ }
738
+ await tester.pump (editableText.cursorBlinkInterval);
739
+ expect (editableText.cursorCurrentlyVisible, equals (isBlinking ? ! initialShowCursor : initialShowCursor));
740
+ await tester.pump (editableText.cursorBlinkInterval);
741
+ expect (editableText.cursorCurrentlyVisible, equals (initialShowCursor));
742
+ await tester.pump (editableText.cursorBlinkInterval ~ / 10 );
743
+ expect (editableText.cursorCurrentlyVisible, equals (initialShowCursor));
744
+ await tester.pump (editableText.cursorBlinkInterval);
745
+ expect (editableText.cursorCurrentlyVisible, equals (isBlinking ? ! initialShowCursor : initialShowCursor));
746
+ await tester.pump (editableText.cursorBlinkInterval);
747
+ expect (editableText.cursorCurrentlyVisible, equals (initialShowCursor));
748
+ }
749
+
750
+ final Offset textfieldStart = tester.getTopLeft (find.byType (EditableText ));
751
+
752
+ await tester.tapAt (textfieldStart + const Offset (50.0 , 9.0 ));
753
+ await tester.pumpAndSettle ();
754
+
755
+ // Before dragging, the cursor should blink.
756
+ await checkCursorBlinking ();
757
+
758
+ final EditableTextState editableTextState = tester.firstState (find.byType (EditableText ));
759
+ editableTextState.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .Start ));
760
+
761
+ // When drag cursor, the cursor shouldn't blink.
762
+ await checkCursorBlinking (isBlinking: false );
763
+
764
+ editableTextState.updateFloatingCursor (RawFloatingCursorPoint (state: FloatingCursorDragState .End ));
765
+ await tester.pumpAndSettle ();
766
+
767
+ // After dragging, the cursor should blink.
768
+ await checkCursorBlinking ();
769
+ });
770
+
704
771
// Regression test for https://github.com/flutter/flutter/pull/30475.
705
772
testWidgets ('Trying to select with the floating cursor does not crash' , (WidgetTester tester) async {
706
773
const String text = 'hello world this is fun and cool and awesome!' ;
0 commit comments