Restart EditableText cursor timer when it moves (#70787)
This commit is contained in:
parent
720f366ff5
commit
0aec2c3d0f
@ -2089,6 +2089,12 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// To keep the cursor from blinking while it moves, restart the timer here.
|
||||
if (_cursorTimer != null) {
|
||||
_stopCursorTimer(resetCharTicks: false);
|
||||
_startCursorTimer();
|
||||
}
|
||||
}
|
||||
|
||||
bool _textChangedSinceLastCaretUpdate = false;
|
||||
|
@ -323,6 +323,81 @@ void main() {
|
||||
EditableText.debugDeterministicCursor = false;
|
||||
});
|
||||
|
||||
testWidgets('Cursor animation restarts when it is moved using keys on desktop', (WidgetTester tester) async {
|
||||
const String testText = 'Some text long enough to move the cursor around';
|
||||
final TextEditingController controller = TextEditingController(text: testText);
|
||||
final Widget widget = MaterialApp(
|
||||
home: EditableText(
|
||||
controller: controller,
|
||||
focusNode: FocusNode(),
|
||||
style: const TextStyle(fontSize: 20.0),
|
||||
maxLines: 1,
|
||||
cursorColor: Colors.blue,
|
||||
backgroundCursorColor: Colors.grey,
|
||||
cursorOpacityAnimates: false,
|
||||
selectionControls: materialTextSelectionControls,
|
||||
keyboardType: TextInputType.text,
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(widget);
|
||||
|
||||
await tester.tap(find.byType(EditableText));
|
||||
await tester.pump();
|
||||
|
||||
final EditableTextState editableTextState = tester.firstState(find.byType(EditableText));
|
||||
final RenderEditable renderEditable = editableTextState.renderEditable;
|
||||
|
||||
await tester.pump();
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
// Android cursor goes from exactly on to exactly off on the 500ms dot.
|
||||
await tester.pump(const Duration(milliseconds: 499));
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowLeft);
|
||||
await tester.pump();
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowLeft);
|
||||
|
||||
await tester.pump();
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 299));
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowRight);
|
||||
|
||||
await tester.pump();
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 299));
|
||||
expect(renderEditable.cursorColor!.alpha, 255);
|
||||
expect(renderEditable, paints..rect(color: const Color(0xff2196f3)));
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(renderEditable.cursorColor!.alpha, 0);
|
||||
expect(renderEditable, paintsExactlyCountTimes(#drawRect, 0));
|
||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.macOS }));
|
||||
|
||||
testWidgets('Cursor does not show when showCursor set to false', (WidgetTester tester) async {
|
||||
const Widget widget = MaterialApp(
|
||||
home: Material(
|
||||
|
Loading…
x
Reference in New Issue
Block a user