setText method

void setText(
  1. String s, {
  2. bool recordHistory = true,
})

Replaces the current text and collapses the selection at the end.

Implementation

void setText(String s, {bool recordHistory = true}) {
  _runEditFrame(() {
    _beginHistoryAction(_TextInputHistoryAction.setText, breakChain: true);
    if (recordHistory) {
      _recordUndoSnapshot();
    }
    final graphemes = textPrepareInsertedGraphemes(
      uni.codePoints(s),
      multiline: multiline,
    );
    final err = _validate(graphemes);
    _setValueInternal(graphemes, err);
    _applyOffsetStateSnapshot(
      TextOffsetStateSnapshot.collapsed(cursorOffset: _value.length),
    );
    _resetDesiredCol();
    _updateSuggestions();
  });
}