Make getRenderEditor() not nullable

pull/579/head
X Code 3 years ago
parent 6c39fcbc54
commit aa10d79d08
  1. 2
      lib/src/widgets/editor.dart
  2. 12
      lib/src/widgets/raw_editor.dart
  3. 8
      lib/src/widgets/raw_editor/raw_editor_state_selection_delegate_mixin.dart
  4. 26
      lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

@ -51,7 +51,7 @@ abstract class EditorState extends State<RawEditor>
implements TextSelectionDelegate { implements TextSelectionDelegate {
ScrollController get scrollController; ScrollController get scrollController;
RenderEditor? getRenderEditor(); RenderEditor getRenderEditor();
EditorTextSelectionOverlay? getSelectionOverlay(); EditorTextSelectionOverlay? getSelectionOverlay();

@ -749,11 +749,11 @@ class RawEditorState extends EditorState
if (widget.scrollable || _scrollController.hasClients) { if (widget.scrollable || _scrollController.hasClients) {
_showCaretOnScreenScheduled = false; _showCaretOnScreenScheduled = false;
final renderEditor = getRenderEditor(); if (!mounted) {
if (renderEditor == null) {
return; return;
} }
final renderEditor = getRenderEditor();
final viewport = RenderAbstractViewport.of(renderEditor); final viewport = RenderAbstractViewport.of(renderEditor);
final editorOffset = final editorOffset =
renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport); renderEditor.localToGlobal(const Offset(0, 0), ancestor: viewport);
@ -777,8 +777,8 @@ class RawEditorState extends EditorState
} }
@override @override
RenderEditor? getRenderEditor() { RenderEditor getRenderEditor() {
return _editorKey.currentContext?.findRenderObject() as RenderEditor?; return _editorKey.currentContext?.findRenderObject() as RenderEditor;
} }
@override @override
@ -806,7 +806,7 @@ class RawEditorState extends EditorState
@override @override
void debugAssertLayoutUpToDate() { void debugAssertLayoutUpToDate() {
getRenderEditor()!.debugAssertLayoutUpToDate(); getRenderEditor().debugAssertLayoutUpToDate();
} }
/// Shows the selection toolbar at the location of the current cursor. /// Shows the selection toolbar at the location of the current cursor.
@ -903,7 +903,7 @@ class RawEditorState extends EditorState
bool get readOnly => widget.readOnly; bool get readOnly => widget.readOnly;
@override @override
TextLayoutMetrics get textLayoutMetrics => getRenderEditor()!; TextLayoutMetrics get textLayoutMetrics => getRenderEditor();
@override @override
AnimationController get floatingCursorResetController => AnimationController get floatingCursorResetController =>

@ -45,11 +45,11 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
@override @override
void bringIntoView(TextPosition position) { void bringIntoView(TextPosition position) {
final localRect = getRenderEditor()!.getLocalRectForCaret(position); final localRect = getRenderEditor().getLocalRectForCaret(position);
final targetOffset = _getOffsetToRevealCaret(localRect, position); final targetOffset = _getOffsetToRevealCaret(localRect, position);
scrollController.jumpTo(targetOffset.offset); 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 // 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); return RevealedOffset(offset: scrollController.offset, rect: rect);
} }
final editableSize = getRenderEditor()!.size; final editableSize = getRenderEditor().size;
final double additionalOffset; final double additionalOffset;
final Offset unitOffset; final Offset unitOffset;
@ -77,7 +77,7 @@ mixin RawEditorStateSelectionDelegateMixin on EditorState
center: rect.center, center: rect.center,
width: rect.width, width: rect.width,
height: math.max( height: math.max(
rect.height, getRenderEditor()!.preferredLineHeight(position)), rect.height, getRenderEditor().preferredLineHeight(position)),
); );
additionalOffset = expandedRect.height >= editableSize.height additionalOffset = expandedRect.height >= editableSize.height

@ -187,7 +187,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
// origin, but the touch origin is used to determine which line the cursor is // 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. // on, we need this offset to correctly render and move the cursor.
Offset _floatingCursorOffset(TextPosition textPosition) => Offset _floatingCursorOffset(TextPosition textPosition) =>
Offset(0, getRenderEditor()!.preferredLineHeight(textPosition) / 2); Offset(0, getRenderEditor().preferredLineHeight(textPosition) / 2);
@override @override
void updateFloatingCursor(RawFloatingCursorPoint point) { void updateFloatingCursor(RawFloatingCursorPoint point) {
@ -202,14 +202,14 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_pointOffsetOrigin = point.offset; _pointOffsetOrigin = point.offset;
final currentTextPosition = final currentTextPosition =
TextPosition(offset: getRenderEditor()!.selection.baseOffset); TextPosition(offset: getRenderEditor().selection.baseOffset);
_startCaretRect = _startCaretRect =
getRenderEditor()!.getLocalRectForCaret(currentTextPosition); getRenderEditor().getLocalRectForCaret(currentTextPosition);
_lastBoundedOffset = _startCaretRect!.center - _lastBoundedOffset = _startCaretRect!.center -
_floatingCursorOffset(currentTextPosition); _floatingCursorOffset(currentTextPosition);
_lastTextPosition = currentTextPosition; _lastTextPosition = currentTextPosition;
getRenderEditor()!.setFloatingCursor( getRenderEditor().setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!); point.state, _lastBoundedOffset!, _lastTextPosition!);
break; break;
case FloatingCursorDragState.Update: case FloatingCursorDragState.Update:
@ -220,23 +220,23 @@ mixin RawEditorStateTextInputClientMixin on EditorState
_startCaretRect!.center + centeredPoint - floatingCursorOffset; _startCaretRect!.center + centeredPoint - floatingCursorOffset;
final preferredLineHeight = final preferredLineHeight =
getRenderEditor()!.preferredLineHeight(_lastTextPosition!); getRenderEditor().preferredLineHeight(_lastTextPosition!);
_lastBoundedOffset = _lastBoundedOffset =
getRenderEditor()!.calculateBoundedFloatingCursorOffset( getRenderEditor().calculateBoundedFloatingCursorOffset(
rawCursorOffset, rawCursorOffset,
preferredLineHeight, preferredLineHeight,
); );
_lastTextPosition = getRenderEditor()!.getPositionForOffset( _lastTextPosition = getRenderEditor().getPositionForOffset(
getRenderEditor()! getRenderEditor()
.localToGlobal(_lastBoundedOffset! + floatingCursorOffset)); .localToGlobal(_lastBoundedOffset! + floatingCursorOffset));
getRenderEditor()!.setFloatingCursor( getRenderEditor().setFloatingCursor(
point.state, _lastBoundedOffset!, _lastTextPosition!); point.state, _lastBoundedOffset!, _lastTextPosition!);
final newSelection = TextSelection.collapsed( final newSelection = TextSelection.collapsed(
offset: _lastTextPosition!.offset, offset: _lastTextPosition!.offset,
affinity: _lastTextPosition!.affinity); affinity: _lastTextPosition!.affinity);
// Setting selection as floating cursor moves will have scroll view // Setting selection as floating cursor moves will have scroll view
// bring background cursor into view // bring background cursor into view
getRenderEditor()! getRenderEditor()
.onSelectionChanged(newSelection, SelectionChangedCause.forcePress); .onSelectionChanged(newSelection, SelectionChangedCause.forcePress);
break; break;
case FloatingCursorDragState.End: case FloatingCursorDragState.End:
@ -259,10 +259,10 @@ mixin RawEditorStateTextInputClientMixin on EditorState
/// and current position of background cursor) /// and current position of background cursor)
void onFloatingCursorResetTick() { void onFloatingCursorResetTick() {
final finalPosition = final finalPosition =
getRenderEditor()!.getLocalRectForCaret(_lastTextPosition!).centerLeft - getRenderEditor().getLocalRectForCaret(_lastTextPosition!).centerLeft -
_floatingCursorOffset(_lastTextPosition!); _floatingCursorOffset(_lastTextPosition!);
if (floatingCursorResetController.isCompleted) { if (floatingCursorResetController.isCompleted) {
getRenderEditor()!.setFloatingCursor( getRenderEditor().setFloatingCursor(
FloatingCursorDragState.End, finalPosition, _lastTextPosition!); FloatingCursorDragState.End, finalPosition, _lastTextPosition!);
_startCaretRect = null; _startCaretRect = null;
_lastTextPosition = null; _lastTextPosition = null;
@ -275,7 +275,7 @@ mixin RawEditorStateTextInputClientMixin on EditorState
final lerpY = final lerpY =
lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!; lerpDouble(_lastBoundedOffset!.dy, finalPosition.dy, lerpValue)!;
getRenderEditor()!.setFloatingCursor(FloatingCursorDragState.Update, getRenderEditor().setFloatingCursor(FloatingCursorDragState.Update,
Offset(lerpX, lerpY), _lastTextPosition!, Offset(lerpX, lerpY), _lastTextPosition!,
resetLerpValue: lerpValue); resetLerpValue: lerpValue);
} }

Loading…
Cancel
Save