@@ -1965,7 +1965,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
19651965 // to make sure the user can see the changes they just made. Programmatical
19661966 // changes to `textEditingValue` do not trigger the behavior even if the
19671967 // text field is focused.
1968- _scheduleShowCaretOnScreen ();
1968+ _scheduleShowCaretOnScreen (withAnimation : true );
19691969 if (_hasInputConnection) {
19701970 // To keep the cursor from blinking while typing, we want to restart the
19711971 // cursor timer every time a new character is typed.
@@ -2498,7 +2498,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
24982498
24992499 bool _showCaretOnScreenScheduled = false ;
25002500
2501- void _scheduleShowCaretOnScreen () {
2501+ void _scheduleShowCaretOnScreen ({ required bool withAnimation} ) {
25022502 if (_showCaretOnScreenScheduled) {
25032503 return ;
25042504 }
@@ -2538,17 +2538,23 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
25382538
25392539 final RevealedOffset targetOffset = _getOffsetToRevealCaret (_currentCaretRect! );
25402540
2541- _scrollController.animateTo (
2542- targetOffset.offset,
2543- duration: _caretAnimationDuration,
2544- curve: _caretAnimationCurve,
2545- );
2546-
2547- renderEditable.showOnScreen (
2548- rect: caretPadding.inflateRect (targetOffset.rect),
2549- duration: _caretAnimationDuration,
2550- curve: _caretAnimationCurve,
2551- );
2541+ if (withAnimation) {
2542+ _scrollController.animateTo (
2543+ targetOffset.offset,
2544+ duration: _caretAnimationDuration,
2545+ curve: _caretAnimationCurve,
2546+ );
2547+ renderEditable.showOnScreen (
2548+ rect: caretPadding.inflateRect (targetOffset.rect),
2549+ duration: _caretAnimationDuration,
2550+ curve: _caretAnimationCurve,
2551+ );
2552+ } else {
2553+ _scrollController.jumpTo (targetOffset.offset);
2554+ renderEditable.showOnScreen (
2555+ rect: caretPadding.inflateRect (targetOffset.rect),
2556+ );
2557+ }
25522558 });
25532559 }
25542560
@@ -2561,7 +2567,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
25612567 _selectionOverlay? .updateForScroll ();
25622568 });
25632569 if (_lastBottomViewInset < WidgetsBinding .instance.window.viewInsets.bottom) {
2564- _scheduleShowCaretOnScreen ();
2570+ // Because the metrics change signal from engine will come here every frame
2571+ // (on both iOS and Android). So we don't need to show caret with animation.
2572+ _scheduleShowCaretOnScreen (withAnimation: false );
25652573 }
25662574 }
25672575 _lastBottomViewInset = WidgetsBinding .instance.window.viewInsets.bottom;
@@ -2745,7 +2753,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
27452753 WidgetsBinding .instance.addObserver (this );
27462754 _lastBottomViewInset = WidgetsBinding .instance.window.viewInsets.bottom;
27472755 if (! widget.readOnly) {
2748- _scheduleShowCaretOnScreen ();
2756+ _scheduleShowCaretOnScreen (withAnimation : true );
27492757 }
27502758 if (! _value.selection.isValid) {
27512759 // Place cursor at the end if the selection is invalid when we receive focus.
@@ -2900,7 +2908,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
29002908 ? _value.selection != value.selection
29012909 : _value != value;
29022910 if (shouldShowCaret) {
2903- _scheduleShowCaretOnScreen ();
2911+ _scheduleShowCaretOnScreen (withAnimation : true );
29042912 }
29052913 _formatAndSetValue (value, cause, userInteraction: true );
29062914 }
0 commit comments