@@ -1965,7 +1965,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
1965
1965
// to make sure the user can see the changes they just made. Programmatical
1966
1966
// changes to `textEditingValue` do not trigger the behavior even if the
1967
1967
// text field is focused.
1968
- _scheduleShowCaretOnScreen ();
1968
+ _scheduleShowCaretOnScreen (withAnimation : true );
1969
1969
if (_hasInputConnection) {
1970
1970
// To keep the cursor from blinking while typing, we want to restart the
1971
1971
// cursor timer every time a new character is typed.
@@ -2498,7 +2498,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2498
2498
2499
2499
bool _showCaretOnScreenScheduled = false ;
2500
2500
2501
- void _scheduleShowCaretOnScreen () {
2501
+ void _scheduleShowCaretOnScreen ({ required bool withAnimation} ) {
2502
2502
if (_showCaretOnScreenScheduled) {
2503
2503
return ;
2504
2504
}
@@ -2538,17 +2538,23 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2538
2538
2539
2539
final RevealedOffset targetOffset = _getOffsetToRevealCaret (_currentCaretRect! );
2540
2540
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
+ }
2552
2558
});
2553
2559
}
2554
2560
@@ -2561,7 +2567,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2561
2567
_selectionOverlay? .updateForScroll ();
2562
2568
});
2563
2569
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 );
2565
2573
}
2566
2574
}
2567
2575
_lastBottomViewInset = WidgetsBinding .instance.window.viewInsets.bottom;
@@ -2745,7 +2753,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
2745
2753
WidgetsBinding .instance.addObserver (this );
2746
2754
_lastBottomViewInset = WidgetsBinding .instance.window.viewInsets.bottom;
2747
2755
if (! widget.readOnly) {
2748
- _scheduleShowCaretOnScreen ();
2756
+ _scheduleShowCaretOnScreen (withAnimation : true );
2749
2757
}
2750
2758
if (! _value.selection.isValid) {
2751
2759
// 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
2900
2908
? _value.selection != value.selection
2901
2909
: _value != value;
2902
2910
if (shouldShowCaret) {
2903
- _scheduleShowCaretOnScreen ();
2911
+ _scheduleShowCaretOnScreen (withAnimation : true );
2904
2912
}
2905
2913
_formatAndSetValue (value, cause, userInteraction: true );
2906
2914
}
0 commit comments