deleteLastCharacter method
Deletes the last character of the current operation.
Implementation
TSimpleOperation deleteLastCharacter() {
final List<String> updatedOperands = List<String>.from(operands);
final int lastIndex = updatedOperands.length - 1;
String? operator = this.operator;
if (lastIndex < 0) {
return clear();
}
if (updatedOperands.length == 1 && operator != null) {
operator = null;
} else if (lastOperand.isNotEmpty) {
updatedOperands[lastIndex] = lastOperand.substring(
0,
lastOperand.length - 1,
);
}
if (updatedOperands.isNotEmpty && updatedOperands.last.isEmpty) {
updatedOperands.removeLast();
}
return TSimpleOperation(
isLastOperandPercent: isLastOperandPercent,
operands: updatedOperands,
operator: operator,
result: result,
);
}