updateFloatingCursor method

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

Updates the floating cursor position and state.

See also:

Implementation

@override
void updateFloatingCursor(RawFloatingCursorPoint point) {
  _floatingCursorResetController ??= AnimationController(
    vsync: this,
  )..addListener(_onFloatingCursorResetTick);
  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;

      final TextPosition 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));
      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;
  }
}