enableUndoRedo method

void enableUndoRedo({
  1. int maxHistorySize = 50,
})

Enables recording. A smaller positive limit trims the oldest snapshots from both stacks. Invalid limits throw without changing history.

Implementation

void enableUndoRedo({int maxHistorySize = 50}) {
  if (!_canChangeHistory) return;
  if (maxHistorySize <= 0) {
    throw ArgumentError.value(
      maxHistorySize,
      'maxHistorySize',
      'Must be positive',
    );
  }
  _maxHistorySize = maxHistorySize;
  _undoRedoEnabled = true;
  for (final stack in [_undoStack, _redoStack]) {
    if (stack.length > _maxHistorySize) {
      stack.removeRange(0, stack.length - _maxHistorySize);
    }
  }
  _publishHistory();
}