delCharFromTextController method

void delCharFromTextController()

Implementation

void delCharFromTextController() {
  final textValue = value;
  final curSelection = textValue.selection;

  var startPos = curSelection.start;
  final endPos = curSelection.end;

  if (startPos == -1 || textValue.text.isEmpty) {
    return;
  }

  if (startPos == endPos) {
    if (startPos > 0) {
      startPos--;
    } else {
      return;
    }
  }

  value = TextEditingValue(
    text: textValue.text.replaceRange(startPos, endPos, ''),
    selection: TextSelection.fromPosition(TextPosition(offset: startPos)),
  );

}