updateFloatingCursor method Null safety

  1. @override
void updateFloatingCursor(
  1. RawFloatingCursorPoint point
)
override

Updates the floating cursor position and state.

Implementation

@override
void updateFloatingCursor(RawFloatingCursorPoint point) {
  switch (point.state) {
    case FloatingCursorDragState.Start:
      if (_floatingCursorResetController.isAnimating) {
        _floatingCursorResetController.stop();
        _onFloatingCursorResetTick();
      }

      // We want to send in points that are centered around a (0,0) origin, so
      // we cache the position.
      _pointOffsetOrigin = point.offset;

      TextPosition currentTextPosition =
      TextPosition(offset: renderEditable.selection!.baseOffset);
      //zmt
      if (supportSpecialText) {
        currentTextPosition = convertTextInputPostionToTextPainterPostion(
            renderEditable.text!, renderEditable.selection!.base);
      } else {
        currentTextPosition =
            TextPosition(offset: renderEditable.selection!.baseOffset);
      }
      _startCaretRect =
          renderEditable.getLocalRectForCaret(currentTextPosition);

      _lastBoundedOffset = _startCaretRect!.center - _floatingCursorOffset;
      _lastTextPosition = currentTextPosition;
      renderEditable.setFloatingCursor(
          point.state, _lastBoundedOffset!, _lastTextPosition!);
      break;
    case FloatingCursorDragState.Update:
      final Offset centeredPoint = point.offset! - _pointOffsetOrigin!;
      final Offset rawCursorOffset =
          _startCaretRect!.center + centeredPoint - _floatingCursorOffset;

      _lastBoundedOffset = renderEditable
          .calculateBoundedFloatingCursorOffset(rawCursorOffset);
      _lastTextPosition = renderEditable.getPositionForPoint(renderEditable
          .localToGlobal(_lastBoundedOffset! + _floatingCursorOffset));
      if (renderEditable.hasSpecialInlineSpanBase) {
        _lastTextPosition = makeSureCaretNotInSpecialText(
            renderEditable.text!, _lastTextPosition!);
      }
      renderEditable.setFloatingCursor(
          point.state, _lastBoundedOffset!, _lastTextPosition!);
      break;
    case FloatingCursorDragState.End:
    // We skip animation if no update has happened.
      if (_lastTextPosition != null && _lastBoundedOffset != null) {
        _floatingCursorResetController.value = 0.0;
        _floatingCursorResetController.animateTo(1.0,
            duration: _floatingCursorResetTime, curve: Curves.decelerate);
      }
      break;
  }
}