diff --git a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart index c5fe8317..0b4904ff 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart @@ -63,7 +63,9 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState final localRect = renderEditor.getLocalRectForCaret(position); final targetOffset = _getOffsetToRevealCaret(localRect, position); - scrollController.jumpTo(targetOffset.offset); + if (scrollController.hasClients) { + scrollController.jumpTo(targetOffset.offset); + } renderEditor.showOnScreen(rect: targetOffset.rect); } @@ -77,7 +79,9 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState // `renderEditable.preferredLineHeight`, before the target scroll offset is // calculated. RevealedOffset _getOffsetToRevealCaret(Rect rect, TextPosition position) { - if (!scrollController.position.allowImplicitScrolling) { + // Make sure scrollController is attached + if (scrollController.hasClients && + !scrollController.position.allowImplicitScrolling) { return RevealedOffset(offset: scrollController.offset, rect: rect); } @@ -102,12 +106,17 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState // No overscrolling when encountering tall fonts/scripts that extend past // the ascent. - final targetOffset = (additionalOffset + scrollController.offset).clamp( - scrollController.position.minScrollExtent, - scrollController.position.maxScrollExtent, - ); + var targetOffset = additionalOffset; + if (scrollController.hasClients) { + targetOffset = (additionalOffset + scrollController.offset).clamp( + scrollController.position.minScrollExtent, + scrollController.position.maxScrollExtent, + ); + } - final offsetDelta = scrollController.offset - targetOffset; + final offsetDelta = + (scrollController.hasClients ? scrollController.offset : 0) - + targetOffset; return RevealedOffset( rect: rect.shift(unitOffset * offsetDelta), offset: targetOffset); }