diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index dca897fa..0b0eff9f 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -51,7 +51,7 @@ abstract class EditorState extends State implements TextSelectionDelegate { ScrollController get scrollController; - RenderEditor? getRenderEditor(); + RenderEditor getRenderEditor(); EditorTextSelectionOverlay? getSelectionOverlay(); diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 20431258..8a646a4f 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -749,11 +749,11 @@ class RawEditorState extends EditorState if (widget.scrollable || _scrollController.hasClients) { _showCaretOnScreenScheduled = false; - final renderEditor = getRenderEditor(); - if (renderEditor == null) { + if (!mounted) { return; } + final renderEditor = getRenderEditor(); final viewport = RenderAbstractViewport.of(renderEditor); final editorOffset = renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport); @@ -777,8 +777,8 @@ class RawEditorState extends EditorState } @override - RenderEditor? getRenderEditor() { - return _editorKey.currentContext?.findRenderObject() as RenderEditor?; + RenderEditor getRenderEditor() { + return _editorKey.currentContext?.findRenderObject() as RenderEditor; } @override @@ -806,7 +806,7 @@ class RawEditorState extends EditorState @override void debugAssertLayoutUpToDate() { - getRenderEditor()!.debugAssertLayoutUpToDate(); + getRenderEditor().debugAssertLayoutUpToDate(); } /// Shows the selection toolbar at the location of the current cursor. @@ -903,7 +903,7 @@ class RawEditorState extends EditorState bool get readOnly => widget.readOnly; @override - TextLayoutMetrics get textLayoutMetrics => getRenderEditor()!; + TextLayoutMetrics get textLayoutMetrics => getRenderEditor(); @override AnimationController get floatingCursorResetController => 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 8c8e64c9..5e8c13bb 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 @@ -45,11 +45,11 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState @override void bringIntoView(TextPosition position) { - final localRect = getRenderEditor()!.getLocalRectForCaret(position); + final localRect = getRenderEditor().getLocalRectForCaret(position); final targetOffset = _getOffsetToRevealCaret(localRect, position); scrollController.jumpTo(targetOffset.offset); - getRenderEditor()!.showOnScreen(rect: targetOffset.rect); + getRenderEditor().showOnScreen(rect: targetOffset.rect); } // Finds the closest scroll offset to the current scroll offset that fully @@ -66,7 +66,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState return RevealedOffset(offset: scrollController.offset, rect: rect); } - final editableSize = getRenderEditor()!.size; + final editableSize = getRenderEditor().size; final double additionalOffset; final Offset unitOffset; @@ -77,7 +77,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState center: rect.center, width: rect.width, height: math.max( - rect.height, getRenderEditor()!.preferredLineHeight(position)), + rect.height, getRenderEditor().preferredLineHeight(position)), ); additionalOffset = expandedRect.height >= editableSize.height diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index a9923d27..c845cedc 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -187,7 +187,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState // origin, but the touch origin is used to determine which line the cursor is // on, we need this offset to correctly render and move the cursor. Offset _floatingCursorOffset(TextPosition textPosition) => - Offset(0, getRenderEditor()!.preferredLineHeight(textPosition) / 2); + Offset(0, getRenderEditor().preferredLineHeight(textPosition) / 2); @override void updateFloatingCursor(RawFloatingCursorPoint point) { @@ -202,14 +202,14 @@ mixin RawEditorStateTextInputClientMixin on EditorState _pointOffsetOrigin = point.offset; final currentTextPosition = - TextPosition(offset: getRenderEditor()!.selection.baseOffset); + TextPosition(offset: getRenderEditor().selection.baseOffset); _startCaretRect = - getRenderEditor()!.getLocalRectForCaret(currentTextPosition); + getRenderEditor().getLocalRectForCaret(currentTextPosition); _lastBoundedOffset = _startCaretRect!.center - _floatingCursorOffset(currentTextPosition); _lastTextPosition = currentTextPosition; - getRenderEditor()!.setFloatingCursor( + getRenderEditor().setFloatingCursor( point.state, _lastBoundedOffset!, _lastTextPosition!); break; case FloatingCursorDragState.Update: @@ -220,23 +220,23 @@ mixin RawEditorStateTextInputClientMixin on EditorState _startCaretRect!.center + centeredPoint - floatingCursorOffset; final preferredLineHeight = - getRenderEditor()!.preferredLineHeight(_lastTextPosition!); + getRenderEditor().preferredLineHeight(_lastTextPosition!); _lastBoundedOffset = - getRenderEditor()!.calculateBoundedFloatingCursorOffset( + getRenderEditor().calculateBoundedFloatingCursorOffset( rawCursorOffset, preferredLineHeight, ); - _lastTextPosition = getRenderEditor()!.getPositionForOffset( - getRenderEditor()! + _lastTextPosition = getRenderEditor().getPositionForOffset( + getRenderEditor() .localToGlobal(_lastBoundedOffset! + floatingCursorOffset)); - getRenderEditor()!.setFloatingCursor( + getRenderEditor().setFloatingCursor( point.state, _lastBoundedOffset!, _lastTextPosition!); final newSelection = TextSelection.collapsed( offset: _lastTextPosition!.offset, affinity: _lastTextPosition!.affinity); // Setting selection as floating cursor moves will have scroll view // bring background cursor into view - getRenderEditor()! + getRenderEditor() .onSelectionChanged(newSelection, SelectionChangedCause.forcePress); break; case FloatingCursorDragState.End: @@ -259,10 +259,10 @@ mixin RawEditorStateTextInputClientMixin on EditorState /// and current position of background cursor) void onFloatingCursorResetTick() { final finalPosition = - getRenderEditor()!.getLocalRectForCaret(_lastTextPosition!).centerLeft - + getRenderEditor().getLocalRectForCaret(_lastTextPosition!).centerLeft - _floatingCursorOffset(_lastTextPosition!); if (floatingCursorResetController.isCompleted) { - getRenderEditor()!.setFloatingCursor( + getRenderEditor().setFloatingCursor( FloatingCursorDragState.End, finalPosition, _lastTextPosition!); _startCaretRect = null; _lastTextPosition = null; @@ -275,7 +275,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState final lerpY = lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!; - getRenderEditor()!.setFloatingCursor(FloatingCursorDragState.Update, + getRenderEditor().setFloatingCursor(FloatingCursorDragState.Update, Offset(lerpX, lerpY), _lastTextPosition!, resetLerpValue: lerpValue); }