undo method

void undo()

Performs undo by removing the last action from history and applying the reverse action.

Implementation

void undo() {
  if (_history[_currentPage]?.isNotEmpty == true) {
    var lastAction = _history[_currentPage]!.removeLast();
    _undoStack[_currentPage]!.add(lastAction);

    if (lastAction.isAdd) {
      _textBoxes[_currentPage]?.remove(
        lastAction.textBox,
      ); // Remove added text box.
    } else {
      _textBoxes[_currentPage]?.add(
        lastAction.textBox,
      ); // Re-add removed text box.
    }
    notifyListeners(); // Notify listeners after undo.
  }
}