diff --git a/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart index 9746711a5..f235c4a17 100644 --- a/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/editor/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -33,15 +33,17 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState void bringIntoView(TextPosition position) { // Ignore errors if position is invalid (i.e. paste on iOS when editor // has no content and user pasted from toolbar) - try { - final localRect = renderEditor.getLocalRectForCaret(position); - final targetOffset = _getOffsetToRevealCaret(localRect, position); - - if (scrollController.hasClients) { - scrollController.jumpTo(targetOffset.offset); - } - renderEditor.showOnScreen(rect: targetOffset.rect); - } catch (_) {} + WidgetsBinding.instance.addPostFrameCallback((_) { + try { + final localRect = renderEditor.getLocalRectForCaret(position); + final targetOffset = _getOffsetToRevealCaret(localRect, position); + + if (scrollController.hasClients) { + scrollController.jumpTo(targetOffset.offset); + } + renderEditor.showOnScreen(rect: targetOffset.rect); + } catch (_) {} + }); } // Finds the closest scroll offset to the current scroll offset that fully