setHistoryLimit method

void setHistoryLimit(
  1. int limit
)

Set the history limit to manage the maximum number of stored states.

This method sets a limit on the number of states that can be stored in the history. If the number of stored states exceeds this limit, the oldest states are removed to free up memory. This is crucial for preventing excessive memory usage, especially when each state includes large data such as screenshots.

  • limit: The maximum number of states to retain in the history. Must be 1 or greater.

Implementation

void setHistoryLimit(int limit) {
  if (limit <= 0) {
    throw ErrorHint('The state history limit must be 1 or greater!');
  }
  while (position > limit) {
    if (position > 0) {
      position--;
      stateHistory.removeAt(0);
      screenshots.removeAt(0);
    } else {
      stateHistory.removeLast();
      screenshots.removeLast();
    }
  }
}